use of com.demo.protocol.HelloRequest in project SpringCloudDemo by RickJou.
the class RibbonController method helloConsumer2.
/**
* 简化版post请求,直接将对象作为消息体提交
*
* @return
*/
@SuppressWarnings("rawtypes")
@HystrixCommand(fallbackMethod = "helloConsumer2FullBack")
@RequestMapping(value = "/ribbon-consumer2", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public String helloConsumer2() {
ServiceInstance serverInstance = lbc.choose("EUREKA-PRODUCER");
// 如果没有服务提供者,那么LoadBalancerClient不能够获取实例,将会导致空指针异常,此时将会使得服务降级不可用.
if (serverInstance != null) {
log.info("load blance is:" + serverInstance.getHost() + ":" + serverInstance.getPort() + "/" + serverInstance.getServiceId());
}
HelloRequest hr = new HelloRequest();
hr.setName("alan");
hr.setSay("configure center get value commonSettingValue:" + commonSettingValue + ",eurekaProducerValue:" + eurekaConsumerRibbonValue);
hr.setRandomId((new Random()).nextLong());
Map response = restTemplate.postForObject(url2, hr, Map.class);
return response.toString();
}
use of com.demo.protocol.HelloRequest in project SpringCloudDemo by RickJou.
the class FeignController method helloConsumer2.
@RequestMapping(value = "/feign-consumer2", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
public String helloConsumer2(RestTemplate restTemplate) {
log.info("feign cosumer2 ......");
ServiceInstance serverInstance = lbc.choose("EUREKA-PRODUCER");
// 如果没有服务提供者,那么LoadBalancerClient不能够获取实例,将会导致空指针异常,此时将会使得服务降级不可用.
if (serverInstance != null) {
log.info("load blance is:" + serverInstance.getHost() + ":" + serverInstance.getPort() + "/" + serverInstance.getServiceId());
}
HelloRequest hr = new HelloRequest();
hr.setName("alan");
hr.setSay("configure center get value commonSettingValue:" + commonSettingValue + ",eurekaProducerValue:" + eurekaConsulmerFeignValue);
hr.setRandomId((new Random()).nextLong());
return sayHelloServer.sayHello2(hr).toString();
}
Aggregations