Example Spring DSL Integration for JPA Inbound Adapter
I cannot find a useful example for polling a JPA source for incoming data. I know how to do this in XML, but cannot figure out how to do this in DSL.
In short, I want to periodically poll the JPA repository for entries and then push the entries to a stream that will do the usual filtering / transforming / executing.
respectfully
David smith
source to share
Connect JpaPollingChannelAdapter
as @Bean
and use
IntegrationFlows.from(jpaMessageSource(),
c -> c.poller(Pollers.fixedDelay(1000)))
.transform(...)
...
Refer to DSL Reference for configuration parameters.
This object is next to the top (with another message source).
source to share
You're right: support for JPA components doesn't exist yet in Spring Integration Java DSL. Feel free to raise JIRA ( JavaDSL
) on this issue and we'll take care of that requirement. Feel free to contribute !
In the meantime, I can help you figure out how to do this without a high level API.
<int-jpa:inbound-channel-adapter>
based on objects JpaPollingChannelAdapter
and JpaExecutor
(they will be used for the DSL API). You just have 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 the framework as usual for existing DSL APIs.
UPDATE
How do I enforce the auto-startup = property when creating the JpaPollingChannelAdapter software? Also, is it possible to get this bean and call .start (),. Stop () using the control bus?
Look, Gary answers. The element Lifecycle
is a responsibility Endpoint
, in our case it is SourcePollingChannelAdapter
. So, you have to provide this second Lambda argument, configure .autoStartup()
and .id()
to be able to insert SourcePollingChannelAdapter
for yours JpaPollingChannelAdapter
and work with it for your purpose. This one id
can actually be used from control-bus
to start()/stop()
at runtime.
Yes, I agree JpaPollingChannelAdapter
- a bad name for this class, because it really is an implementation MessageSource
.
source to share