【问题标题】:spring integration jms traceabilityspring 集成 jms 可追溯性
【发布时间】:2018-12-20 19:30:29
【问题描述】:

我们需要在基于 Spring Integration 的控制器模块中为传入和传出的 JMS 消息添加可追溯性(添加 trace-id 和 spell-id)。任何人都可以帮助我使用可用于此的拦截器,它可以拦截所有进入 JMS 队列的请求以及将发送到队列中的所有请求。

下面是sn-p的代码:

            <!-- Need to trace the message once we receive in incoming_queue -->
            <int-jms:message-driven-channel-adapter id="jmsIn" channel="channel_1" 
            destination-name="incoming_queue"></int-jms:message-driven-channel-adapter>   

            <!-- Need to trace the message before we send the message to outgoing_queue -->
            <int-jms:outbound-channel-adapter id="jmsOut" 
                    channel="channel_1" connection-factory="connectionFactory"
                    destination-name="outgoing_queue"/>

谢谢

【问题讨论】:

    标签: spring-integration


    【解决方案1】:

    两边都有一个DefaultJmsHeaderMapper 和这个JavaDoc:

    * This implementation copies JMS API headers (e.g. JMSReplyTo) to and from
     * Spring Integration Messages. Any user-defined properties will also be copied
     * from a JMS Message to a Spring Integration Message, and any other headers
     * on a Spring Integration Message (beyond the JMS API headers) will likewise
     * be copied to a JMS Message. Those other headers will be copied to the
     * general properties of a JMS Message whereas the JMS API headers are passed
     * to the appropriate setter methods (e.g. setJMSReplyTo).
    

    所以,如果您的 trace-idspell-id 属于兼容类型:

    private static List<Class<?>> SUPPORTED_PROPERTY_TYPES = Arrays.asList(new Class<?>[] {
            Boolean.class, Byte.class, Double.class, Float.class, Integer.class, Long.class, Short.class, String.class });
    

    您可以发送和接收这些标头。

    如果您考虑记录这些标头,您绝对可以查看ChannelInterceptor 实现以在向/从 JMS 发送/接收之前/之后记录这些标头。

    【讨论】:

    • 非常感谢 Artem。我能够实现我想做的事情。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    • 1970-01-01
    • 2014-08-23
    • 2013-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多