Cron JDBCSpring与注释的集成

Cron JDBCSpring与注释的集成,cron,annotations,spring-integration,spring-jdbc,Cron,Annotations,Spring Integration,Spring Jdbc,我正在看一个带有注释类的示例,完全没有XML: <int-jdbc:inbound-channel-adapter query="select * from item where status=2" channel="target" data-source="dataSource" update="update item set status=10 where id in (:id)" /> 或 也许有更好的解决方案,比如输入消息网关,通过使用CRON语句查询数据库来创建入

我正在看一个带有注释类的示例,完全没有XML:

<int-jdbc:inbound-channel-adapter query="select * from item where status=2"
channel="target" data-source="dataSource"
update="update item set status=10 where id in (:id)" />


也许有更好的解决方案,比如输入消息网关,通过使用CRON语句查询数据库来创建入口点。
Cron编程查询->第一个通道Java和Annotation配置变量:

@Bean
public PollerMetadata poller(PlatformTransactionManager transactionManager) {
    PeriodicTrigger trigger = new PeriodicTrigger(1000);
    trigger.setFixedRate(true);

    MatchAlwaysTransactionAttributeSource attributeSource = new MatchAlwaysTransactionAttributeSource();
    attributeSource.setTransactionAttribute(new DefaultTransactionAttribute());
    TransactionInterceptor interceptor = new TransactionInterceptor(transactionManager, attributeSource);

    PollerMetadata poller = new PollerMetadata();
    poller.setTrigger(trigger);
    poller.setAdviceChain(Collections.singletonList(interceptor));
    return poller;
}

@Bean
@InboundChannelAdapter(value = "target", poller = @Poller("poller"))
public MessageSource<?> counterMessageSource(DataSource dataSource) {
    JdbcPollingChannelAdapter adapter =
            new JdbcPollingChannelAdapter(dataSource, "select * from item where status = 2");
    adapter.setUpdateSql("update item set status = 10 where id in (:id)");
    return adapter;
}

请随时提出针对DSL项目的GH问题,以便为JDBC适配器提供DSL。

!。非常感谢。现在我正试图理解poller.setAdviceChain(Collections.singletonList(interceptor))的含义。我收到一个错误,因为它需要不同的类型:PollerMetadata类型中的方法setAdviceChain(List)不适用于参数(List)。请尝试此
poller.setAdviceChain(Collections.singletonList(interceptor))-该方法应为泛型。@Artem Bilan:如何获得您在第二个代码段中引用的
transactionManager
?谢谢。
transactionManager
是一个bean参考。在我的代码片段中,我使用了对
@Bean
方法的引用。但是你可以用任何可能的方法注射它
@Bean
public PollerMetadata poller(PlatformTransactionManager transactionManager) {
    PeriodicTrigger trigger = new PeriodicTrigger(1000);
    trigger.setFixedRate(true);

    MatchAlwaysTransactionAttributeSource attributeSource = new MatchAlwaysTransactionAttributeSource();
    attributeSource.setTransactionAttribute(new DefaultTransactionAttribute());
    TransactionInterceptor interceptor = new TransactionInterceptor(transactionManager, attributeSource);

    PollerMetadata poller = new PollerMetadata();
    poller.setTrigger(trigger);
    poller.setAdviceChain(Collections.singletonList(interceptor));
    return poller;
}

@Bean
@InboundChannelAdapter(value = "target", poller = @Poller("poller"))
public MessageSource<?> counterMessageSource(DataSource dataSource) {
    JdbcPollingChannelAdapter adapter =
            new JdbcPollingChannelAdapter(dataSource, "select * from item where status = 2");
    adapter.setUpdateSql("update item set status = 10 where id in (:id)");
    return adapter;
}
@Bean
public MessageSource<?> jdbcAdapter(DataSource dataSource) {
    JdbcPollingChannelAdapter adapter =
            new JdbcPollingChannelAdapter(dataSource, "select * from item where status = 2");
    adapter.setUpdateSql("update item set status = 10 where id in (:id)");
    return adapter;
}

@Bean
public IntegrationFlow jdbcFlow(MessageSource<?> jdbcAdapter) {
    return IntegrationFlows
            .from(jdbcAdapter, e ->
                    e.poller(p -> p.fixedRate(1000).transactional(transactionManager())))
            .channel(c -> c.direct("target"))
            .get();
}