Reputation: 1
I am quite new to Spring Integration and need to figure out solution in my work.
What I need to do is:
- Provide polling mechanism from db.
- Should be able to enable/disable polling when certain condition occurs
- Need timeout for polling (for example if status doesnt change for 5 min minutes do stomething)
- Need to pass data to polling mechanism
Basically its all what I need. I was thinking about using Spring's task:scheduled-tasks but I cant see option for manually enabling/disabling task and setting timeout. Data that needs to be passed to polling mechanism can be stored in Spring bean. Could you guys advise if I am stepping into right direction or should I try other aproach?
Upvotes: 0
Views: 1306
Reputation: 2137
here's a simple example of how to poll a database with spring integration
<int-jdbc:inbound-channel-adapter
id="jdbcPoller" channel="jdbc.poll.channel"
data-source="dataSource" query="select count(*) from test_table">
<int:poller fixed-rate="500" task-executor="pollTaskExecutor"/>
</int-jdbc:inbound-channel-adapter>
<int:channel id="jdbc.poll.channel"/>
if you wanted to stop it conditionally, you could do something like this
//stop the polling
AbstractEndpoint poller = context.getBean("jdbcPoller",AbstractEndpoint.class);
poller.stop();
Upvotes: 1
Reputation: 174739
Using Spring Integration, you can use a <int-jdbc:inbound-channel-adapter/>
. You can start/stop it using the Lifecycle methods
isRunning()
, start()
, stop()
.
Or, you can send messages to a <control-bus/>
to start/stop.
There are a number of ways to detect no activity (e.g. using JMX to look at the message count for the channel etc).
Upvotes: 0
Reputation: 29997
You can use task:scheduled-tasks
, and you'll need to implement the bits you want, as spring doesn't provide all the features you want OOTB.
The disable bit, can be done by the task checking if it was disabled, and thus not do anything.
About the time out, your code needs to figure out what does "status doesn't change" and "do something".
Need to pass data to polling mechanism: the polling mechanism can load the data it requires, or read it from a source (queue, shared object, etc).
Upvotes: 0