zoukankan      html  css  js  c++  java
  • springcloud 微服务之间传递token解决方案

    在springcloud 微服务中大部分是通过token来验证用户的,那么有个问题,假设现在有A服务,B服务,外部使用RESTApi请求调用A服务,在请求头上有token字段,A服务使用完后,B服务也要使用,如何才能把token也转发到B服务呢,最差的解决办法就是吧token放到请求参数中,但是这样第一个是明文传输,第二个是比较麻烦,前端每次都要加个参数。
    这里可以使用Feign的RequestInterceptor,把request里的请求参数包括请求头全部复制到feign的request里,但是直接使用一般情况下HttpServletRequest上下文对象是为空的,其实加个配置就可以解决。

    1.服务A中 application.yml 加入如下配置

    hystrix:
      command:
        default:
          execution:
            isolation:
              strategy: SEMAPHORE  #加上这个就可以获取到HttpServletRequest
              thread:
                timeoutInMilliseconds: 10000
    

    2.服务A中加入 FeginInterceptor

    若服务B或C也想传递token,加上上述A配置即可



    作者:码农笔录
    链接:https://www.jianshu.com/p/f6ed1c6e6653
    来源:简书

  • 相关阅读:
    TUXEDO启动常见错误和解决方法 动常见错误和解决方法
    tuxedo远程客户端无法访问类故障(持续更新ing)
    ORA-00845: MEMORY_TARGET not supported on this system
    vim使用方法
    GP_CAT:209: ERROR: Write error 27, file /app/dir/dom/log/ULOG.011508
    txuedo TMS_ORACLE启动失败
    type类型定义
    oralce
    登录指定端口的ftp_server
    Failed to initialize NVML: Driver/library version mismatch
  • 原文地址:https://www.cnblogs.com/wxhbk/p/12550497.html
Copyright © 2011-2022 走看看