hystrix
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
package com.forezp;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableDiscoveryClient
|
||||
@EnableFeignClients
|
||||
public class ServiceFeignApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ServiceFeignApplication.class, args);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package com.forezp.service;
|
||||
|
||||
import org.springframework.cloud.netflix.feign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
/**
|
||||
* Created by fangzhipeng on 2017/4/6.
|
||||
*/
|
||||
@FeignClient(value = "service-hi",fallback = SchedualServiceHiHystric.class)
|
||||
public interface SchedualServiceHi {
|
||||
@RequestMapping(value = "/hi",method = RequestMethod.GET)
|
||||
String sayHiFromClientOne(@RequestParam(value = "name") String name);
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package com.forezp.service;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Created by fangzhipeng on 2017/4/6.
|
||||
*/
|
||||
@Component
|
||||
public class SchedualServiceHiHystric implements SchedualServiceHi {
|
||||
@Override
|
||||
public String sayHiFromClientOne(String name) {
|
||||
return "sorry "+name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.forezp.web;
|
||||
|
||||
import com.forezp.service.SchedualServiceHi;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Created by fangzhipeng on 2017/4/6.
|
||||
*/
|
||||
@RestController
|
||||
public class HiController {
|
||||
|
||||
@Autowired
|
||||
SchedualServiceHi schedualServiceHi;
|
||||
@RequestMapping(value = "/hi",method = RequestMethod.GET)
|
||||
public String sayHi(@RequestParam String name){
|
||||
return schedualServiceHi.sayHiFromClientOne(name);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
eureka:
|
||||
client:
|
||||
serviceUrl:
|
||||
defaultZone: http://localhost:8761/eureka/
|
||||
server:
|
||||
port: 8765
|
||||
spring:
|
||||
application:
|
||||
name: service-feign
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.forezp;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class ServiceFeignApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user