英文:
How do I make the update query executed by JdbcPollingChannelAdapter transactional?
问题
Sure, here is the translated code portion:
@Configuration
@EnableIntegration
public class IntegrationMain {
@Bean
public MessageChannel aChannel() {
return new DirectChannel();
}
@Splitter(inputChannel = "inChannel", outputChannel = "outChannel")
public List<myEntity> splitter(Message message) {
// Your splitter logic here
}
@Bean
@InboundChannelAdapter(value = "inChannel", poller = @Poller(fixedDelay = "2000"))
public MessageSource<?> pollDbForQuery(DataSource dataSource) {
JdbcPollingChannelAdapter myAdapter = new JdbcPollingChannelAdapter(dataSource, SQL);
myAdapter.setRowMapper();
myAdapter.setUpdateSql("update query");
return adapter;
}
}
If you have any further questions or need assistance with the code, please feel free to ask.
英文:
@Configuration
@EnableIntegration
public class IntergrationMain{
@Bean
public MessageChannel aChannel() {
return new DirectChannel();
}
@Splitter(inputChannel = "inChannel", outputChannel = "outChannel")
public List<myEnity> splitter(Message message) {
}
@Bean
@InboundChannelAdapter(value = "inChannel", poller = @Poller(fixedDelay = "2000"))
public MessageSource<?> pollDbForQuery(DataSource dataSource) {
JdbcPollingChannelAdapter myAdapter = new JdbcPollingChannelAdapter(dataSource, SQL);
myAdapter.setRowMapper();
myAdapter.setUpdateSql("update query");
retrun adapter;
}
}
I want to make the update query that is executed by the jdbcPollingadapter to become transactional. I saw some examples on the web but they were using a builder for Pollers and provide transaction support by setting a method called setAdvice()
. I'm not able to achieve something similar using the JdbcPollingChannelAdapter right now.
答案1
得分: 1
查看 @Poller
注解:
/**
* @return {@link org.springframework.integration.scheduling.PollerMetadata} bean 的名称。
*/
String value() default "";
所以,您需要配置一个 PollerMetadata
bean,使用 PeriodicTrigger
并设置 Duration.ofSeconds(2)
。还有一个 setAdviceChain()
选项,您可以注入 TransactionInterceptor
。
这在文档中有明确说明:https://docs.spring.io/spring-integration/docs/current/reference/html/configuration.html#configuration-using-poller-annotation
英文:
See @Poller
annotation:
/**
* @return The {@link org.springframework.integration.scheduling.PollerMetadata} bean
* name.
*/
String value() default "";
So, you need to configure a PollerMetadata
bean with a PeriodicTrigger
for that Duration.ofSeconds(2)
. And there is a setAdviceChain()
option where you can inject a TransactionInterceptor
.
And that is clearly explained in docs: https://docs.spring.io/spring-integration/docs/current/reference/html/configuration.html#configuration-using-poller-annotation
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论