【发布时间】:2018-12-18 22:22:39
【问题描述】:
我有一个 JdbcPollingChannelAdapter 定义如下:
@Bean
public MessageSource<Object> jdbcMessageSource(DataSource dataSource) {
JdbcPollingChannelAdapter jdbcPollingChannelAdapter = new JdbcPollingChannelAdapter(dataSource,
"SELECT * FROM common_task where due_at <= NOW() and retries < order by due_at ASC FOR UPDATE SKIP LOCKED");
jdbcPollingChannelAdapter.setMaxRowsPerPoll(1);
jdbcPollingChannelAdapter.setUpdateSql("Update common_task set retries = :retries, due_at = due_at + interval '10 minutes' WHERE ID = (:id)");
jdbcPollingChannelAdapter.setUpdatePerRow(true);
jdbcPollingChannelAdapter.setRowMapper(this::mapRow);
jdbcPollingChannelAdapter.setUpdateSqlParameterSourceFactory(this::updateParamSource);
return jdbcPollingChannelAdapter;
}
为此的集成流程:
@Bean
public IntegrationFlow pollingFlow(MessageSource<Object> jdbcMessageSource) {
return IntegrationFlows.from(jdbcMessageSource,
c -> c.poller(Pollers.fixedRate(250, TimeUnit.MILLISECONDS)
.maxMessagesPerPoll(1)
.transactional()))
.split()
.channel(taskSourceChannel())
.get();
}
服务激活器定义为
@ServiceActivator(inputChannel = "taskSourceChannel")
public void doSomething(FooTask event) {
//do something but ** not ** within the transaction of the poller.
}
集成流中的轮询器被定义为事务性的。根据我的理解,这将 1、在事务中执行选择查询和更新查询。 2. 它也会在同一个事务中执行doSomething()方法。
目标:我想做 1 而不是 2。我想在事务中进行选择和更新,以确保两者都发生。但是,我不想在同一个事务中执行 doSomething()。如果 doSomething() 中出现异常,我仍然希望保留在轮询期间所做的更新。我怎样才能做到这一点?
【问题讨论】:
标签: spring-integration spring-integration-dsl