Spring Integration : How to guarantee the transaction two more jdbc-outbound-gateway?

梦想的初衷 提交于 2020-01-09 11:31:26

问题


I have the following pattern

I have two kinds of databases. One is a internal database where it saves data from 5 json datas from http inbound gateways. The Other is a external database where it saves final refiend data from 5 jsons saved tables.

The Process is like the followings.


  • One Transaction

    ① Each message is saved to each table and return status to the client where it sends data.


  • Second Transaction

    ② If 5 kinds of datas are completed to receive, it activate one service activator where queries 5 tables and make 3 kinds of refined data that will save in external database.

    ③ The next connected channel type is a publish-subscribe channel.

    ④ There are 3 kinds of subscribe channel to deliver each jdbc-outbound-gateway for saving data to external database. (There is a rowmapper process to handle saving multiple rows)

How can I set the transaction for being guaranteed? Please let me know elaborately.


回答1:


Add a QueueChannel somewhere upstream (i.e. before the pub sub channel for tx2) and use a <transactional/> poller to start the transaction.

Alternatively, insert a transactional gateway...

<int:service-activator ... ref="txGw" />

<int:gateway ... service-interface="TX" />

public interface TX {
    @Transactional
    Message<?> exchange(Message<?> m);
}

You'll need <tx:annotation-driven /> to enable transactions in the second case.



来源:https://stackoverflow.com/questions/26419602/spring-integration-how-to-guarantee-the-transaction-two-more-jdbc-outbound-gat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!