简体   繁体   中英

Transaction boundary of spring integration splitter

The base question is actually very simple, lets consider the following chain:

<int:poller id="inputPoller" task-executor="inputTaskPool" fixed-delay="${input.poller.interval}"
            receive-timeout="${input.poller.timeout}" max-messages-per-poll="${poller.messages}">
    <int:transactional transaction-manager="chainedTransactionManager"/>
</int:poller>

<int:chain id="someInputChain" input-channel="theInputChannel">
    <int:poller ref="inputPoller" />
    <!-- various transfomers, nothing asynchronous -->
    <int:splitter id="messageSplitter" ref="messageSplitterService" apply-sequence="false" />
    <int:transformer id="messagePersister" ref="messagePersisterService" method="persistMessageMetadata" />
</int:chain>

Will all messages generated by the messageSplitter be in the same transaction and in the same thread or can it be that they are subsequently handled in different transactions/from different threads?

The splitter calls (synchronously) a REST service that will give it the list of destination channels a message has to go. It will then create so many copies and set a header to the output channel. That list is returned from the splitter. The messagePersister will store the key of the new messages in a database table together with some metadata.

Is each call of messagePersisterService.persistMessageMetadata (for each splitted message) in the same transaction/thread as the original message or will they be handled each in their own transaction?

In Spring Integration nothing goes to a new thread, unless you say that explicitly. Since you have a <int:splitter> withing <chain> , it is really going to produce splitted items one by one to the next handler in the chain. Everything happens on the same thread in the task initiated by the <poller> and, in your case, within TX.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM