diff --git a/cloud-consumer-order80/src/main/java/com/atguigu/springcloud/config/ApplicationContextConfig.java b/cloud-consumer-order80/src/main/java/com/atguigu/springcloud/config/ApplicationContextConfig.java index 6b3099a..c70fa53 100644 --- a/cloud-consumer-order80/src/main/java/com/atguigu/springcloud/config/ApplicationContextConfig.java +++ b/cloud-consumer-order80/src/main/java/com/atguigu/springcloud/config/ApplicationContextConfig.java @@ -1,5 +1,6 @@ package com.atguigu.springcloud.config; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; @@ -12,7 +13,7 @@ public class ApplicationContextConfig { @Bean -// @LoadBalanced + @LoadBalanced public RestTemplate getRestTemplate(){ return new RestTemplate(); } diff --git a/cloud-consumer-order80/src/main/java/com/atguigu/springcloud/controller/OrderController.java b/cloud-consumer-order80/src/main/java/com/atguigu/springcloud/controller/OrderController.java index affd0df..c757646 100644 --- a/cloud-consumer-order80/src/main/java/com/atguigu/springcloud/controller/OrderController.java +++ b/cloud-consumer-order80/src/main/java/com/atguigu/springcloud/controller/OrderController.java @@ -41,7 +41,9 @@ public CommonResult create(Payment payment){ @GetMapping("/consumer/payment/get/{id}") public CommonResult getPaymentById(@PathVariable("id") Long id){ - return restTemplate.getForObject(PAYMENT_URL+"/payment/get/"+id,CommonResult.class); + CommonResult result = restTemplate.getForObject(PAYMENT_URL + "/payment/get/" + id, CommonResult.class); + System.out.println("服务请求回来******"+result.getMessage()); + return result; } @GetMapping("/consumer/custom/payment/get/{id}") diff --git a/cloud-consumer-order80/src/main/resources/application.yml b/cloud-consumer-order80/src/main/resources/application.yml index e0f7094..73d5bb6 100644 --- a/cloud-consumer-order80/src/main/resources/application.yml +++ b/cloud-consumer-order80/src/main/resources/application.yml @@ -19,5 +19,10 @@ eureka: instance-id: order80 prefer-ip-address: true - - +#服务提供者的项目名称不可以小写,小写配置不起作用,亲测过 +#负载均衡机制是在@LoadBalanced注解基础之上的,如果使用类文件达到负载均衡 +#需要重写IRule接口并在主启动类上开启@RibbonClient(name = "CLOUD-PAYMENT-SERVICE",configuration = MySelfRule.class) +#CLOUD-PAYMENT-SERVICE: +# ribbon: +# NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule +# com.netflix.loadbalancer.WeightedResponseTimeRule diff --git a/cloud-provider-payment8001/src/main/resources/application.yml b/cloud-provider-payment8001/src/main/resources/application.yml index 3c66d05..41a94a3 100644 --- a/cloud-provider-payment8001/src/main/resources/application.yml +++ b/cloud-provider-payment8001/src/main/resources/application.yml @@ -32,4 +32,6 @@ eureka: #eureka客户端向服务器发送心跳的时间间隔(默认30秒) lease-renewal-interval-in-seconds: 1 #eruka服务器收到最后一次心跳等待时间上线(默认90秒) - lease-expiration-duration-in-seconds: 2 \ No newline at end of file + lease-expiration-duration-in-seconds: 2 + +