码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • SpringCloud-Gateway无法使用Feign服务(2021.X版本)


    Spring Cloud Gateway 2021.x版本,无法使用Feign调用其他服务接口。

    问题原因:

    在官网的 issue 里面找到了相关的问题。

    How to call another micro-service on GatewayFilterFactory ? · Issue #1090 · spring-cloud/spring-cloud-gateway · GitHubHello, Can you tell me how to call another micro-service on a GatewayFilterFactory? I want to call the authentication micro-service when a request come from user. 1st, I tried to use feign client. but I can not get the ServletRequestAttr...icon-default.png?t=N7T8https://github.com/spring-cloud/spring-cloud-gateway/issues/1090

     Spring Cloud Gateway 2021.x版本 基于WebFlux实现,使用webclient 替换 feign。

    使用案例:

    1. import com.alibaba.fastjson.JSONObject;
    2. import org.slf4j.Logger;
    3. import org.slf4j.LoggerFactory;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.http.HttpHeaders;
    6. import org.springframework.http.MediaType;
    7. import org.springframework.stereotype.Component;
    8. import org.springframework.web.reactive.function.client.WebClient;
    9. import reactor.core.publisher.Mono;
    10. /**
    11. * @Author: meng
    12. * @Description: 权限工具类
    13. * @Date: 2023/8/3 15:01
    14. * @Version: 1.0
    15. */
    16. @Component
    17. public class AuthUtils {
    18. private static Logger logger = LoggerFactory.getLogger(AuthUtils.class);
    19. public final static String LB = "lb://";
    20. @Autowired
    21. private WebClient.Builder webBuilder;
    22. public String getAesKeyByAppId(String appId) {
    23. JSONObject jsonObject = new JSONObject();
    24. jsonObject.put("appId", appId);
    25. try {
    26. Mono result = webBuilder.baseUrl(LB + "服务名称")
    27. .build()
    28. .post()
    29. .uri("uri")
    30. .contentType(MediaType.APPLICATION_JSON)
    31. .header(HttpHeaders.AUTHORIZATION, "token")
    32. .bodyValue(jsonObject)
    33. .retrieve()
    34. .bodyToMono(String.class);
    35. String body = result.toFuture().get();
    36. logger.info("body:{}", body);
    37. // 处理逻辑
    38. ...
    39. }
    40. catch (Exception e) {
    41. logger.error("Exception:{}", e);
    42. }
    43. return null;
    44. }
    45. }

  • 相关阅读:
    大学生个人网站作业 超简单DIV CSS个人网页成品 简单个人网站作业模板 HTML个人网页设计下载 简约黑白色个人主页
    卡码网语言基础课 |句子缩写
    【自然语言处理】【检索】GENER:自回归实体检索
    使用patch-package保存node_modules包修改
    cobbler装机
    基于二次型性能指标的燃料电池过氧比RBF-PID控制
    Unity打包基础(未完)
    18数藏解析
    arm2 day6
    【李航统计学习笔记】第十章:隐马尔科夫模型
  • 原文地址:https://blog.csdn.net/W_Meng_H/article/details/134318475
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号