1
votes

With Spring Integration, is it possible to dynamically create additional inbound channel adapters as the program runs?

Background: I'm pretty new to SI and S-Batch. I'm using SI to poll our db for info that I use to create jobs in SB. Essentially, there are business rules for when the records I am pulling from the DB need to turn into a job. I'm planning on making an inbound channel adapter for each rule. For instance, the rule for items in their initial state would be:

<int-jdbc:inbound-channel-adapter query="select [id] from [MY_DATA] where status_name = 'INITIAL'" .... />

I plan on retrieving the rule info and parsing them into adapters. Instead of the hard coded rule above, I would retrieve the status_name "INITIAL" from the db and use that to build the adapter.

1

1 Answers

1
votes

Yes, you can do that. You should instantiate SourcePollingChannelAdapter and set the MessageSource<?> for it and other important options, like beanFactory and outputChannel. After that you should start() the first one to begin polling.

But... Is that needed at all? Please, be more specific. What is the reason do that?

Maybe there is another solution with managed components?..

UPDATE

SourcePollingChannelAdapter is the main component to manage polling (scheduling) and MessageChannel. The hard task for producing messages is lie on the shoulders of MessageSource<?>. For your JDBC case there is JdbcPollingChannelAdapter.

Yes, you should inject to your service BeanFactory and maybe MessageChannel for those dynamic adapters. I'm not sure that you will be able to populate your dynamic adapters back to the application context.

See this example for more info: https://github.com/spring-projects/spring-integration-samples/tree/master/advanced/dynamic-ftp