Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If syncSend is used to send a message exchange, the implied semantic is that the transaction flows with the exchange and that the provider has to answer synchronously and enlist any needed resources inside the transaction. By setting the autoEnlistInTransaction flag to true on the container, each time a JBI exchange is sent,  it will be enlisted in the current transaction as shown below:Image Added
 
Transactions within a synchronous flow are not created by default. Currently, the only ServiceMix component able to start transactions is the servicemix-jms when used with JCA.

If send is used, the act of sending the message will be enlisted in the current transaction, but the exchange processing will be defered and handled in its own thread. To use transactions with asynchronous message exchanges, the JCA flow must be used. As shown below, the scope of a transaction is bounded by the asynchronous message exchange.
Image Added
Responding to a transactional synchronous message may not be always a possible option for a given component acting as a provider.
For example, an asynchronous BPEL process may not support this processing behavior.

...

Sending synchronous transactional exchanges

Code Block
langjava
  TransactionManager tm = (TransactionManager) getContext().getTransactionManager();
  tm.begin();
  
  InOnly me = createInOnly();
  getContext().getDeliveryChannel().sendSync(me);
  
  tm.commit();
Code Block
langjava
  TransactionManager tm = (TransactionManager) getContext().getTransactionManager();
  tm.begin();
  
  InOut me = createInOut();
  getContext().getDeliveryChannel().sendSync(me);
  // retrieve the out message
  me.setStatus(ExchangeStatus.DONE);
  getContext().getDeliveryChannel().sendSync(me);
  
  tm.commit();

Sending asynchronous transactional exchanges

Code Block
langjava
  TransactionManager tm = (TransactionManager) getContext().getTransactionManager();
  tm.begin();
  
  InOnly me = createInOnly();
  getContext().getDeliveryChannel().send(me);
  
  tm.commit();
Code Block
langjava
  TransactionManager tm = (TransactionManager) getContext().getTransactionManager();
  tm.begin();
  
  InOut me = createInOut();
  getContext().getDeliveryChannel().send(me);
  
  tm.commit();

Receiving and processing transactional exchanges

...

You can check if a given exchange is transactional by using:

Code Block
langjava
  boolean transactional = exchange.getProperty("javax.jbi.transaction.jta") != null;

and you can check if the exchange is synchronous by using:

Code Block
langjava
  boolean synchronous = exchange.getProperty("javax.jbi.messaging.sendSync") != null;

...