Andriy Kryvtsun Andriy Kryvtsun - 1 month ago 13
Java Question

Transaction manager definition for Spring Integration JMS endpoint

In Spring Integration XML DSL is ability to specify transaction manager for JMS message-driven channel adapter:

<int-jms:message-driven-channel-adapter id="..."
connection-factory="..." destination="..."
channel="..." error-channel="errorChannel"
transaction-manager="processTransactionManager" auto-startup="false"/>


How to add transaction manager to my exist SI Java DSL

Jms.messageDrivenChannelAdapter(...)
.destination(...)
.outputChannel(...)
.errorChannel(errorChannel)
.autoStartup(false)
.get();


I wouldn't not use
Jms.channel(...)
DSL call here cause I have to rework my exit flow.

Answer

Like this:

Jms.messageDrivenChannelAdapter(
        Jms.container(this.jmsConnectionFactory, ...)
            .transactionManager(...)
            .get())

There is Jms.messageDrivenChannelAdapter() to accept AbstractMessageListenerContainer implementation and as you see top-level builder from the Jms.container() factory.

UPDATE

For SI Java DSL 1.1.x the workaround is like:

  1. Use Jms.messageDrivenChannelAdapter(AbstractMessageListenerContainer)
  2. Configure top-level @Bean for the DefaultMessageListenerContainer
  3. And use its setTransactionManager()