2016-04-25 12 views
2

2つのjms outbound-channel-adapterがpub-subチャネルから読み取ってトランザクションに参加させたいというシナリオがあります。言い換えれば、私は両方の人にメッセージを書いたり、誰にも書いたりしたくない。私が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からの接続を取得します。

答えて

2

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>フック。 Keep transaction within Spring Integration flow

+0

私のフローのコンポーネントはトランザクションを共有できないが、トランザクションの境界が何であるかを指定する必要があるという問題ではありません。すべてのフローに対して、Springは「始まり」のトランザクションを開始するだけではありません – neesh

+1

M-m-m。あなたがそれを言っていなければ、Springはトランザクションを開始しません。 'sessionTransacted'について知っていることはすべて、特定の呼び出しのためのJMSセッション内のローカルTXまでです。グローバルトランザクションは、それらの2つのJMS呼び出しの前に、上流側で制御する必要があります。 –

関連する問題