【问题标题】:How to Inject String property to javax.jms.TextMessage in Spring Integration如何在 Spring 集成中将字符串属性注入 javax.jms.TextMessage
【发布时间】:2015-09-14 11:12:08
【问题描述】:

我想知道有没有办法在 Spring Integration 中为 JMS 文本消息添加属性。

例如,如果我们使用普通的 JMS 代码,我们总是可以使用以下代码为其设置属性。

message.setStringProperty( "AuctionType", "Reverse" );

编辑

我尝试添加 Spring 文档中给出的标题,但现在我为每条消息获得相同的消息 ID,但由于我打算将其用作 ID,所以我需要它对每条消息都不同。 下面是我的 Spring 配置快照。

<bean class="com.learn.util.RandomMsgId" id="randomMsgId" factory-method="getRndMsgId" scope="prototype"/>

<int:header-enricher input-channel="xmlToJMS"
    output-channel="xmltoJMSwithId">
    <int:header name="MsgId" ref="randomMsgId"/>
</int:header-enricher>

【问题讨论】:

    标签: java spring spring-integration spring-jms


    【解决方案1】:

    使用&lt;header-enricher/&gt; 将自定义标头添加到 spring 集成消息中,它们将映射到 JMS 标头。

    请参阅 the documentationhere

    【讨论】:

    • 您将标头设置为在初始化期间注入的固定值。不要使用原型 bean,使用 &lt;header ... expression="@randomMsgId. getRndMsgId()" /&gt; 将针对每条消息进行评估。
    猜你喜欢
    • 2017-03-05
    • 1970-01-01
    • 2021-11-07
    • 2012-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多