0

I am thinking to create a Spring Integration Spring Boot application to

1-Poll messages from a DB
2-Do some processing on it
3-Publish messages to EMS Queue

using Atomikos for Transaction management. My question is: If the above configuration will be transactional with all the required JTA configurations done? Also I have read somewhere, if multiple threads are created in Spring Integration,e.g,using a Splitter, then the context won't to transactional. How to overcome this?

Pravat Panda
  • 1,060
  • 2
  • 13
  • 27

2 Answers2

1

If you configure the poller as transactional, the flow will run in a transaction, as long as you don't hand off to another thread (via an ExecutorChannel or QueueChannel channel, for example).

Adding a splitter will not break the transaction boundary as each split will be processed on the same thread.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • If I use inbound channel adapter to poll messages from DB and then pass to splitter, converter, publisher to queue via outbound channel adapter etc , is there any way to cover the whole process in a transaction? – Pravat Panda Mar 20 '17 at 13:51
  • Sorry, I wrote parser instead of poller (not enough coffee). Yes, configure the poller to be transactional; the transaction will start before the source is polled and commit when the downstream flow completes. – Gary Russell Mar 20 '17 at 13:54
0

Spring Integration has different requirements for transactions, to Do so you need to pass a transaction manager in the poller metaData, for example:

@Bean
    public PollerMetadata pollerMetadata() throws  NamingException   {
        return Pollers.fixedDelay(Long.valueOf(env.getProperty("poller.interval")))
                .transactional(**transactionManager**).get();
    }

With

 @Autowired
     private PlatformTransactionManager **transactionManager**;

And putting :

@InboundChannelAdapter(channel = "jpaInputChannel", poller = @Poller(value = "**pollerMetadata**"))
Hafsa Ch
  • 43
  • 9