• Feign


    3.2.2 支付微服务提供者Controller修改

    1. @GetMapping("/payment/getInfo")
    2. public ResponseResult getInfo() {
    3. try {
    4. Thread.sleep(3000);
    5. } catch (InterruptedException e) {
    6. e.printStackTrace();
    7. }
    8. String value = UUID.randomUUID().toString() + ":" + serverPort;
    9. return new ResponseResult(200, "成功", value);
    10. }

    3.2.3.订单微服务消费者server

    1. package cn.bdqn.service;
    2. import cn.bdqn.bean.ResponseResult;
    3. import org.springframework.cloud.openfeign.FeignClient;
    4. import org.springframework.stereotype.Component;
    5. import org.springframework.web.bind.annotation.GetMapping;
    6. import org.springframework.web.bind.annotation.PathVariable;
    7. @Component
    8. @FeignClient(name="springcloud-payment-provider-service")
    9. public interface PaymentFeignServer {
    10. @GetMapping("/payment/get/{id}")
    11. public ResponseResult queryId(@PathVariable(name = "id") Integer id);
    12. @GetMapping("/payment/getInfo")
    13. public ResponseResult getInfo();
    14. }

    3.2.4.订单微服务消费者controller

    1. package cn.bdqn.controller;
    2. import cn.bdqn.bean.ResponseResult;
    3. import cn.bdqn.service.PaymentFeignServer;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.web.bind.annotation.GetMapping;
    6. import org.springframework.web.bind.annotation.PathVariable;
    7. import org.springframework.web.bind.annotation.RestController;
    8. @RestController
    9. public class OrderController {
    10. @Autowired
    11. private PaymentFeignServer paymentFeiginService;
    12. @GetMapping(value = "/consumer/payment/get/{id}")
    13. public ResponseResult getPaymentByID(@PathVariable("id") Integer id) {
    14. return paymentFeiginService.queryId(id);
    15. }
    16. @GetMapping(value = "/consumer/payment/getInfo")
    17. public ResponseResult getInfo() {
    18. return paymentFeiginService.getInfo();
    19. }
    20. }

    3.2.6解决方案

    1. server:
    2. port: 80
    3. eureka:
    4. client:
    5. register-width-eureka: false
    6. service-url: # 配置服务中心,openFeign去里面找服务
    7. defaultZone: http://eureka7001.com:7001/eureka/,
    8. http://eureka7002.com:7002/eureka/,
    9. http://eureka7003.com:7003/eureka/,
    10. instance:
    11. prefer-ip-address: true,
    12. ribbon:
    13. #指的是建立连接后从服务器读取到可用资源所用的时间
    14. ReadTimeout: 5000
    15. #指的是建立连接所用的时间 适用于网络状态正常的情况下,两端连接所用的时间
    16. ConnectTimeout: 5000

    4.3配置日志Bean

    1. package cn.bdqn.config;
    2. import feign.Logger;
    3. import org.springframework.context.annotation.Bean;
    4. import org.springframework.context.annotation.Configuration;
    5. @Configuration
    6. public class FeignLogConfig {
    7. @Bean
    8. public Logger.Level feignLoggerLever(){
    9. return Logger.Level.FULL;
    10. }
    11. }

     4.4YML 文件里需要开启日志的Feign客户端

    1. server:
    2. port: 80
    3. eureka:
    4. client:
    5. register-width-eureka: false
    6. service-url: # 配置服务中心,openFeign去里面找服务
    7. defaultZone: http://eureka7001.com:7001/eureka/,
    8. http://eureka7002.com:7002/eureka/,
    9. http://eureka7003.com:7003/eureka/,
    10. instance:
    11. prefer-ip-address: true,
    12. ribbon:
    13. #指的是建立连接后从服务器读取到可用资源所用的时间
    14. ReadTimeout: 5000
    15. #指的是建立连接所用的时间 适用于网络状态正常的情况下,两端连接所用的时间
    16. ConnectTimeout: 5000
    17. logging:
    18. level:
    19. cn.bdqn.service.PaymentFeignService: debug

    ​​​​​​​

  • 相关阅读:
    Android自定义控件属性函数
    Next.js 13 服务器组件和应用目录完整指南
    想要精通算法和SQL的成长之路 - N皇后问题
    SpringMVC学习篇(六)
    Mac下使用nvm,执行微信小程序自定义处理命令失败
    【HTML】HTML作业---管理系统界面
    21【模板方法设计模式】
    css设置输入框边框无效或者不展示边框
    [游戏开发][Unity] UGUI上使用 ParticleSystem支持排序渲染
    c语言的链接(静态链接和动态链接)以及a.out的简述
  • 原文地址:https://blog.csdn.net/zyu67/article/details/132794515