[英]Spring boot - Threads / Feign-Client / Messaging / Streamlistener
We struggle to find a solution for the following scenario:我们努力为以下场景找到解决方案:
Situation情况
Receive a message via Spring Cloud Streamlistener通过 Spring Cloud Streamlistener 接收消息
Invoke a REST-Service via Feign-Client通过 Feign-Client 调用 REST-Service
We have configured several Feign-RequestInterceptor to enrich request header data.我们配置了几个 Feign-RequestInterceptor 来丰富请求头数据。
We want to avoid passing every request header on the method call and like the central configuration approach of the request interceptors.我们希望避免在方法调用上传递每个请求头,并像请求拦截器的中央配置方法一样。
Problem:问题:
How to access data from a specific message, which contains informations, that need to be added to every request call via the Feign-RequestInterceptor.如何从包含信息的特定消息中访问数据,这些信息需要通过 Feign-RequestInterceptor 添加到每个请求调用中。 We don't have a Request-Context, as we come from a message.
我们没有请求上下文,因为我们来自消息。
Can we be sure , that the message consumption and the REST call is happening on the same thread?我们可以确定消息消费和 REST 调用发生在同一个线程上吗? If yes, we could use the NamedThreadLocal to store the information.
如果是,我们可以使用 NamedThreadLocal 来存储信息。
是的,除非您RestTemplate
给 StreamListener 中的另一个线程,否则其余调用将在同一线程上进行(假设您使用的是RestTemplate
而不是反应式 Web 客户端)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.