簡體   English   中英

同一事務中的出站通道適配器

[英]Outbound channel adapters in the same transaction

我有一個場景,其中兩個 jms 出站通道適配器從發布訂閱通道讀取,我希望它們參與交易。 換句話說,我想把信息寫給他們兩個或一個都不寫。 即使我將 session-transacted 設置為 true,這似乎也不會發生。 這是我的配置:

<int:publish-subscribe-channel id="test.pubsub" ignore-failures="false" ></int:publish-subscribe-channel>



        <jms:outbound-channel-adapter channel="test.pubsub" order="1" destination-name="${outbound.queue}" session-transacted="true"
             connection-factory="${connection.factory}"></jms:outbound-channel-adapter>

        <jms:outbound-channel-adapter id="jmsOutputMirror" session-transacted="true"
                    destination-name="${outbound.queue.mirror}"
                    connection-factory="${connection.factory}"
                     channel="test.pubsub" order="2">
        </jms:outbound-channel-adapter>

它們都從 CachingConnectionFactory 獲得連接。

session-transaction在那里對您沒有幫助:

/**
 * Set the transaction mode that is used when creating a JMS {@link Session}.
 * Default is "false".
 * <p>Note that within a JTA transaction, the parameters passed to
 * {@code create(Queue/Topic)Session(boolean transacted, int acknowledgeMode)}
 * method are not taken into account. Depending on the Java EE transaction context,
 * the container makes its own decisions on these values. Analogously, these
 * parameters are not taken into account within a locally managed transaction
 * either, since the accessor operates on an existing JMS Session in this case.
 * <p>Setting this flag to "true" will use a short local JMS transaction
 * when running outside of a managed transaction, and a synchronized local
 * JMS transaction in case of a managed transaction (other than an XA
 * transaction) being present. This has the effect of a local JMS
 * transaction being managed alongside the main transaction (which might
 * be a native JDBC transaction), with the JMS transaction committing
 * right after the main transaction.
 * @see javax.jms.Connection#createSession(boolean, int)
 */
public void setSessionTransacted(boolean sessionTransacted) {
    this.sessionTransacted = sessionTransacted;
}

如果您對它們的調用都未包裝到 TX。 由於您很幸運並且在同一線程中調用了兩個適配器,因此只需要將發送到test.pubsub的消息包裝到 TX 中即可。 例如,該頻道前面的一些@Transactional @Gateway 或者任何其他可能的<tx:advice>鈎子。 你甚至可以考慮這個解決方案: 在 Spring Integration 流中保留事務

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM