我找不到轮询入站数据的JPA源的有用示例。我知道如何在XML中执行此操作,但无法弄清楚它是如何在DSL中完成的。
简而言之,我想要做的是定期轮询JPA存储库以获取记录,然后将记录放入将执行常规过滤/转换/执行的流程中。
亲切的问候
大卫史密斯
答案 0 :(得分:2)
将JpaPollingChannelAdapter
连接为@Bean
并使用
IntegrationFlows.from(jpaMessageSource(),
c -> c.poller(Pollers.fixedDelay(1000)))
.transform(...)
...
有关配置选项,请参阅DSL Reference。
这个靠近顶部(有不同的消息来源)。
答案 1 :(得分:2)
您是对的:Spring Integration Java DSL中还没有JPA组件支持。请随意就此问题提出JIRA(JavaDSL
组件),我们会关注此需求。也欢迎contribute!
与此同时,我可以帮助您了解如何在没有高级API的情况下实现这一目标。
<int-jpa:inbound-channel-adapter>
基于JpaPollingChannelAdapter
和JpaExecutor
个对象(我们将用于DSL API)。您只需为@Bean
配置JpaExecutor
并按照以下方式使用它:
@Bean
public JpaExecutor jpaExecutor(EntityManagerFactory entityManagerFactory) {
JpaExecutor jpaExecutor = new JpaExecutor(entityManagerFactory);
jpaExecutor.setJpaQuery("from Foo");
....
return jpaExecutor;
}
@Bean
public IntegrationFlow jpaFlow(JpaExecutor jpaExecutor) {
return IntegrationFlows.from(new JpaPollingChannelAdapter(jpaExecutor))
.split()
.transform()
....
}
其他所有内容都将通过现有DSL组件API的常规框架完成。
<强>更新强>
如何以编程方式创建JpaPollingChannelAdapter时提供auto-startup =属性?此外,是否可以使用控制总线获取此bean并调用.start(),. stop()?
见加里的回答。 Lifecycle
控件是Endpoint
的责任,在我们的情况下是SourcePollingChannelAdapter
。因此,您应该指定第二个Lambda参数,配置.autoStartup()
和.id()
,以便能够为SourcePollingChannelAdapter
注入JpaPollingChannelAdapter
并为此目的操作它。 <{1}}实际上可以在运行时从id
到control-bus
使用。
是的,我同意start()/stop()
是该类的不幸名称,因为它实际上是JpaPollingChannelAdapter
实现。