You are right: there is no yet JPA components support in the Spring Integration Java DSL. Feel free to raise a JIRA (JavaDSL
component) on the matter and we'll take care about this demand. Feel free to contribute as well!
Meanwhile I can help you to figure out how to do that without high-level API.
The <int-jpa:inbound-channel-adapter>
is based on the JpaPollingChannelAdapter
and JpaExecutor
objects (exactly them we will use for DSL API). You just must to configure @Bean
for JpaExecutor
and use it like this:
@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()
....
}
Everything else will be done by framework as usual for existing DSL components API.
UPDATE
How to provide auto-startup= property when creating JpaPollingChannelAdapter programmatically? Also, is it possible to get this bean and invoke .start(), .stop() using control-bus?
See, Gary's answer. The Lifecycle
control is a responsibility of Endpoint
in our case it is SourcePollingChannelAdapter
. So, you should specify that second Lambda argument, configure the .autoStartup()
and .id()
there to be able to inject the SourcePollingChannelAdapter
for your JpaPollingChannelAdapter
and operate with it for your purpose. That id
really can be used from control-bus
to start()/stop()
at runtime.
Yes, I agree JpaPollingChannelAdapter
is unfortunate name for that class because it is really a MessageSource
implementation.