如何使JdbcPollingChannelAdapter执行的更新查询具有事务性?

huangapple go评论59阅读模式
英文:

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 = &quot;inChannel&quot;, outputChannel = &quot;outChannel&quot;)
public List&lt;myEnity&gt; splitter(Message message) {

}
@Bean
@InboundChannelAdapter(value = &quot;inChannel&quot;, poller = @Poller(fixedDelay = &quot;2000&quot;))
public MessageSource&lt;?&gt; pollDbForQuery(DataSource dataSource) {
    JdbcPollingChannelAdapter myAdapter = new JdbcPollingChannelAdapter(dataSource, SQL); 
    myAdapter.setRowMapper();
    myAdapter.setUpdateSql(&quot;update query&quot;);
    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 &quot;&quot;;

所以,您需要配置一个 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 &quot;&quot;;

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

huangapple
  • 本文由 发表于 2023年4月17日 19:29:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76034677.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定