【问题标题】:How to inject a variable in threadlocal in spring integration flow如何在 Spring 集成流程中的 threadlocal 中注入变量
【发布时间】:2019-10-11 12:52:46
【问题描述】:

我需要在 Spring 集成流程中将 callContext 对象作为线程 Local 注入。在 jms 标头中接收到的 traceId 应在 callContext 对象中提取 n 集,以便在项目级别配置的日志中打印。

IntegrationFlows.from(Jms.messageDrivenChannelAdapter(connectionFactory).destination(topicName))
.log(INFO, m-> “message received for: + ((Order)m.getPayload()).getOrderId())
.handle(orderService)
.get();

【问题讨论】:

    标签: spring-integration spring-integration-dsl


    【解决方案1】:

    您可以在 orderService 中执行此操作,或在其前面添加其他服务。

    【讨论】:

      【解决方案2】:

      我想说Functionlog() 运算符让您可以完全控制要登录消息的内容。当然,也可以避免使用ThreadLocal 的开销。但是,如果您仍然想使用它,我建议您在 log() 之前添加一个 .wireTap(),这样您就可以在您的 ThreadLocal(MDC?)中存储一个值,而不会影响主流程。

      只有你必须记住以某种方式清理 callContext 以避免线程局部污染的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-07-06
        • 1970-01-01
        • 1970-01-01
        • 2016-05-21
        • 2016-03-02
        • 2019-03-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多