Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.springframework.cloud.netflix.feign.FeignClient;
- import org.springframework.http.MediaType;
- import org.springframework.web.bind.annotation.RequestHeader;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.ResponseBody;
- @FeignClient(
- name = "my-service",
- fallback = MyClientFallback.class
- )
- public interface MyClient {
- @RequestMapping(value = "/do/stuff",
- method = RequestMethod.GET,
- produces = {MediaType.APPLICATION_JSON_VALUE})
- @ResponseBody
- boolean myServiceMethod();
- }
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Component;
- import org.springframework.web.bind.annotation.RequestHeader;
- @Component
- public class MyClientFallback implements MyClient {
- @Autowired
- AlertBroadcaster broadcaster;
- @Override
- public boolean myServiceMethod() {
- broadcaster.alert("Failed to contact external service.");
- return false;
- }
- }
- @EnableSwagger2
- @SpringBootApplication
- @EnableMongoRepositories
- @EnableDiscoveryClient
- @EnableZuulProxy
- @EnableFeignClients
- @EnableHystrix
- public class Application {
- public static void main(String[] args) {
- SpringApplication.run(Application.class, args);
- }
- @Bean
- public AlertBroadcaster alertBroadcaster() {
- return new AlertBroadcaster();
- }
- @Bean
- public MyClientFallback myClientFallback() {
- return new MyClientFallback();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement