SyntaxHighlighter

Wednesday, July 4, 2012

Spring Integration - Managing a Service at Runtime


one of the neat tricks to having Spring Integration running is being able to dynamically stop/start it based on other environmental factors.  that is, we've got a long running, Spring Integration polling process going, checking for and processing files every few seconds.  now, at a certain interval during the day, we start a batch process which needs all the resources it can get.  so, whether or not this is a regularly scheduled event, we want to pause the file processor until such time as the batch job is complete.

how?

we can use a Control Bus


in this situation, the solution can be to setup a separate process that monitors or listens for the batch start event.  when a 'positive' event is received, a message is then sent to the Spring Integration Control Bus to 'start'/'stop' certain components.  in the example included below, the business case is as follows;

1. poll a directory for files every x interval
2. poll a database for a result every y interval
3. if the database poll comes back positive, stop the directory/file polling
4. if the database poll comes back negative, resume the directory/file polling

here's the Spring Integrations for the file process

file monitor



monitor the batch process



datasource config (for testing purposes)



task executor configs



hopefully this will help with the problem of dynamically monitoring

No comments:

Post a Comment