Skip to content

Commit

Permalink
add fallback method
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongyuanzhao000 committed Apr 29, 2020
1 parent 1c228c7 commit ade814c
Show file tree
Hide file tree
Showing 51 changed files with 421 additions and 14 deletions.
29 changes: 16 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,24 @@
<!--<module>1_services_analysis_mvn</module>-->
</modules>

<!--<dependencyManagement>-->
<!--<dependencies>-->
<!--<dependency>-->
<!--<groupId>org.springframework.cloud</groupId>-->
<!--<artifactId>spring-cloud-sleuth</artifactId>-->
<!--<version>1.2.3.BUILD-SNAPSHOT</version>-->
<!--<type>pom</type>-->
<!--<scope>import</scope>-->
<!--</dependency>-->
<!--</dependencies>-->
<!--</dependencyManagement>-->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Edgware.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
Expand Down Expand Up @@ -103,7 +102,6 @@
<version>2.4.0</version>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand All @@ -126,6 +124,11 @@
<version>1.2.31</version>
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>

</dependencies>

<!--<repositories>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.integration.annotation.IntegrationComponentScan;
Expand All @@ -18,6 +19,7 @@
@EnableAsync
@IntegrationComponentScan
@EnableSwagger2
@EnableCircuitBreaker
public class AdminBasicInfoApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import adminbasic.entity.*;
import adminbasic.service.AdminBasicInfoService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import edu.fudan.common.util.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -16,6 +20,9 @@
*/
@RestController
@RequestMapping("/api/v1/adminbasicservice")
@DefaultProperties(defaultFallback = "fallback", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")
})
public class AdminBasicInfoController {

@Autowired
Expand All @@ -29,141 +36,165 @@ public String home(@RequestHeader HttpHeaders headers) {

@CrossOrigin(origins = "*")
@GetMapping(path = "/adminbasic/contacts")
@HystrixCommand
public HttpEntity getAllContacts(@RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Find All Contacts by admin ");
return ok(adminBasicInfoService.getAllContacts(headers));
}

@CrossOrigin(origins = "*")
@DeleteMapping(path = "/adminbasic/contacts/{contactsId}")
@HystrixCommand
public HttpEntity deleteContacts(@PathVariable String contactsId, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Delete Contacts by admin ");
return ok(adminBasicInfoService.deleteContact(contactsId, headers));
}

@CrossOrigin(origins = "*")
@PutMapping(path = "/adminbasic/contacts")
@HystrixCommand
public HttpEntity modifyContacts(@RequestBody Contacts mci, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Contacts by admin: ");
return ok(adminBasicInfoService.modifyContact(mci, headers));
}

@CrossOrigin(origins = "*")
@PostMapping(path = "/adminbasic/contacts")
@HystrixCommand
public HttpEntity addContacts(@RequestBody Contacts c, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Contacts by admin ");
return ok(adminBasicInfoService.addContact(c, headers));
}

@CrossOrigin(origins = "*")
@GetMapping(path = "/adminbasic/stations")
@HystrixCommand
public HttpEntity getAllStations(@RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Find All Station by admin ");
return ok(adminBasicInfoService.getAllStations(headers));
}

@CrossOrigin(origins = "*")
@DeleteMapping(path = "/adminbasic/stations")
@HystrixCommand
public HttpEntity deleteStation(@RequestBody Station s, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Delete Station by admin ");
return ok(adminBasicInfoService.deleteStation(s, headers));
}

@CrossOrigin(origins = "*")
@PutMapping(path = "/adminbasic/stations")
@HystrixCommand
public HttpEntity modifyStation(@RequestBody Station s, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Station by admin ");
return ok(adminBasicInfoService.modifyStation(s, headers));
}

@CrossOrigin(origins = "*")
@PostMapping(path = "/adminbasic/stations")
@HystrixCommand
public HttpEntity addStation(@RequestBody Station s, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Station by admin");
return ok(adminBasicInfoService.addStation(s, headers));
}

@CrossOrigin(origins = "*")
@GetMapping(path = "/adminbasic/trains")
@HystrixCommand
public HttpEntity getAllTrains(@RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Find All Train by admin: ");
return ok(adminBasicInfoService.getAllTrains(headers));
}

@CrossOrigin(origins = "*")
@DeleteMapping(path = "/adminbasic/trains/{id}")
@HystrixCommand
public HttpEntity deleteTrain(@PathVariable String id, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Delete Train by admin");
return ok(adminBasicInfoService.deleteTrain(id, headers));
}

@CrossOrigin(origins = "*")
@PutMapping(path = "/adminbasic/trains")
@HystrixCommand
public HttpEntity modifyTrain(@RequestBody TrainType t, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Train by admin ");
return ok(adminBasicInfoService.modifyTrain(t, headers));
}

@CrossOrigin(origins = "*")
@PostMapping(path = "/adminbasic/trains")
@HystrixCommand
public HttpEntity addTrain(@RequestBody TrainType t, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Train by admin ");
return ok(adminBasicInfoService.addTrain(t, headers));
}

@CrossOrigin(origins = "*")
@GetMapping(path = "/adminbasic/configs")
@HystrixCommand
public HttpEntity getAllConfigs(@RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Find All Config by admin ");
return ok(adminBasicInfoService.getAllConfigs(headers));
}

@CrossOrigin(origins = "*")
@DeleteMapping(path = "/adminbasic/configs/{name}")
@HystrixCommand
public HttpEntity deleteConfig(@PathVariable String name, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Delete Config by admin ");
return ok(adminBasicInfoService.deleteConfig(name, headers));
}

@CrossOrigin(origins = "*")
@PutMapping(path = "/adminbasic/configs")
@HystrixCommand
public HttpEntity modifyConfig(@RequestBody Config c, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Config by admin ");
return ok(adminBasicInfoService.modifyConfig(c, headers));
}

@CrossOrigin(origins = "*")
@PostMapping(path = "/adminbasic/configs")
@HystrixCommand
public HttpEntity addConfig(@RequestBody Config c, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Config by admin ");
return ok(adminBasicInfoService.addConfig(c, headers));
}

@CrossOrigin(origins = "*")
@GetMapping(path = "/adminbasic/prices")
@HystrixCommand
public HttpEntity getAllPrices(@RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Find All Price by admin ");
return ok(adminBasicInfoService.getAllPrices(headers));
}

@CrossOrigin(origins = "*")
@DeleteMapping(path = "/adminbasic/prices")
@HystrixCommand
public HttpEntity deletePrice(@RequestBody PriceInfo pi, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Delete Price by admin ");
return ok(adminBasicInfoService.deletePrice(pi, headers));
}

@CrossOrigin(origins = "*")
@PutMapping(path = "/adminbasic/prices")
@HystrixCommand
public HttpEntity modifyPrice(@RequestBody PriceInfo pi, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Modify Price by admin ");
return ok(adminBasicInfoService.modifyPrice(pi, headers));
}

@CrossOrigin(origins = "*")
@PostMapping(path = "/adminbasic/prices")
@HystrixCommand
public HttpEntity addPrice(@RequestBody PriceInfo pi, @RequestHeader HttpHeaders headers) {
AdminBasicInfoController.LOGGER.info("[Admin Basic Info Service][Add Price by admin");
return ok(adminBasicInfoService.addPrice(pi, headers));
}

private HttpEntity fallback() {
return ok(new Response<>(0, null, null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.integration.annotation.IntegrationComponentScan;
Expand All @@ -18,6 +19,7 @@
@EnableAsync
@IntegrationComponentScan
@EnableSwagger2
@EnableCircuitBreaker
public class AdminOrderApplication {
public static void main(String[] args) {
SpringApplication.run(AdminOrderApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import adminorder.entity.*;
import adminorder.service.AdminOrderService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import edu.fudan.common.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
Expand All @@ -14,6 +18,9 @@
*/
@RestController
@RequestMapping("/api/v1/adminorderservice")
@DefaultProperties(defaultFallback = "fallback", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")
})
public class AdminOrderController {

@Autowired
Expand All @@ -26,23 +33,31 @@ public String home(@RequestHeader HttpHeaders headers) {

@CrossOrigin(origins = "*")
@GetMapping(path = "/adminorder")
@HystrixCommand
public HttpEntity getAllOrders(@RequestHeader HttpHeaders headers) {
return ok(adminOrderService.getAllOrders(headers));
}

@PostMapping(value = "/adminorder")
@HystrixCommand
public HttpEntity addOrder(@RequestBody Order request, @RequestHeader HttpHeaders headers) {
return ok(adminOrderService.addOrder(request, headers));
}

@PutMapping(value = "/adminorder")
@HystrixCommand
public HttpEntity updateOrder(@RequestBody Order request, @RequestHeader HttpHeaders headers) {
return ok(adminOrderService.updateOrder(request, headers));
}

@DeleteMapping(value = "/adminorder/{orderId}/{trainNumber}")
@HystrixCommand
public HttpEntity deleteOrder(@PathVariable String orderId, @PathVariable String trainNumber, @RequestHeader HttpHeaders headers) {
return ok(adminOrderService.deleteOrder(orderId, trainNumber, headers));
}


private HttpEntity fallback() {
return ok(new Response<>(0, null, null));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.integration.annotation.IntegrationComponentScan;
Expand All @@ -18,6 +19,7 @@
@EnableAsync
@IntegrationComponentScan
@EnableSwagger2
@EnableCircuitBreaker
public class AdminRouteApplication {
public static void main(String[] args) {
SpringApplication.run(AdminRouteApplication.class, args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import adminroute.entity.RouteInfo;
import adminroute.service.AdminRouteService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import edu.fudan.common.util.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
Expand All @@ -14,6 +18,9 @@
*/
@RestController
@RequestMapping("/api/v1/adminrouteservice")
@DefaultProperties(defaultFallback = "fallback", commandProperties = {
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "5000")
})
public class AdminRouteController {

@Autowired
Expand All @@ -26,17 +33,25 @@ public String home(@RequestHeader HttpHeaders headers) {

@CrossOrigin(origins = "*")
@GetMapping(path = "/adminroute")
@HystrixCommand
public HttpEntity getAllRoutes(@RequestHeader HttpHeaders headers) {
return ok(adminRouteService.getAllRoutes(headers));
}

@PostMapping(value = "/adminroute")
@HystrixCommand
public HttpEntity addRoute(@RequestBody RouteInfo request, @RequestHeader HttpHeaders headers) {
return ok(adminRouteService.createAndModifyRoute(request, headers));
}

@DeleteMapping(value = "/adminroute/{routeId}")
@HystrixCommand
public HttpEntity deleteRoute(@PathVariable String routeId, @RequestHeader HttpHeaders headers) {
return ok(adminRouteService.deleteRoute(routeId, headers));
}


private HttpEntity fallback() {
return ok(new Response<>(0, null, null));
}
}
Loading

0 comments on commit ade814c

Please sign in to comment.