Hello guyz,
I'd like to use multithreading for each component of my spring integration in my project. Here is an example XML configuration:
I've read that you can use task-executors for multithreading. But as I understood it - you have to define it per each channel, per each component. That sucks imho. Please correct me If I'm wrong.Code:<poller default="true" id="poller" time-unit="SECONDS" fixed-delay="60"/> <beans:bean id="inboundFileToStringsSplitter" class="com.shopping.si.splitter.InboundFileToStringsSplitter" /> <beans:bean id="inboundStringToOscarSaleDataTransformer" class="com.shopping.si.transformer.InboundStringToOscarSaleDataTransformer" /> <beans:bean id="inboundOscarSaleDataProcessor" class="com.shopping.si.sa.InboundOscarSaleDataSA"/> <beans:bean id="successPointsServiceActivator" class="com.shopping.si.sa.SuccessPointsSA" /> <channel id="inboundFileChannel"/> <channel id="inboundStringChannel"/> <channel id="inboundOscarSaleDataChannel"/> <channel id="successPointsChannel" /> <file:inbound-channel-adapter directory="${com.shopping.listen.dir}" channel="inboundFileChannel" id="fileChannelAdapter" /> <splitter id="fileToStringsSplitter" input-channel="inboundFileChannel" output-channel="inboundStringChannel" ref="inboundFileToStringsSplitter" /> <transformer id="stringToOscarSaleDataTransformer" input-channel="inboundStringChannel" output-channel="inboundOscarSaleDataChannel" ref="inboundStringToOscarSaleDataTransformer" /> <service-activator id="saInboundOscarSaleDataProcessor" input-channel="inboundOscarSaleDataChannel" ref="inboundOscarSaleDataProcessor" /> <service-activator id="saSuccessPointsServiceActivator" input-channel="successPointsChannel" ref="successPointsServiceActivator" />
P.S.: little offtopic question: channel-queue - what that queue actually does ? As I understood, channel will collect N messages defined by queue property and only then processes them. Am I right or wrong?
Mine idea was if spring would allow (or better automatically handle this) to define some property, like "threads" for each (not every each, but most) component and create defined amount of threads to process messages.
Illustraiting on the example above what I want to accomplish:
1) <file:inbound-channel-adapter directory="${com.shopping.listen.dir}" channel="inboundFileChannel" id="fileChannelAdapter" />
Well, I don't really mind if that one works with one file w/o multiply processing. But as option it would be nice to have something like:
So that will mean: InboundChannelAdapter, if you see 2 files in specified directory, please create 2 instances/threads of inboundFileToStringsSplitter and process the simulatenously. This will actually should tell splitted to create 2 instances of it as well.Code:<file:inbound-channel-adapter directory="${com.shopping.listen.dir}" channel="inboundFileChannel" id="fileChannelAdapter" concurrent-files="2" />
Maybe it is hard to handle, but OK - i can accept that should work only with 1 file at the time. But lets continue.
2) inboundFileToStringsSplitter splits fileLines to strings and send them to the transformer inboundStringChannel. Here I DEFINATELY want to have the following option:
So if there were 100 string lines passed to the inboundStringChannel it would create 100 instances/threads of transformer and process them simulatenously. I think this is pretty easy to implement.Code:<transformer id="stringToOscarSaleDataTransformer" input-channel="inboundStringChannel" output-channel="inboundOscarSaleDataChannel" ref="inboundStringToOscarSaleDataTransformer" threads="100" />
3) Transformer sends data to the inboundOscarSaleDataChannel which is handled by ServiceActivator. Here I want just the same threads property to process incoming messages simulatenously. For example: SpringIntegration sees that there more messages in that channel, but the current service activator is still busy - just go ahead and create new instance of SA and process it.
So in conclusion, I'd like to ask all two following questions:
1) Why spring still doesn't have such easy to implement features ? Or they are not that easy to implement at all ? What difficulties could be faced in that case ?
2) Which is currently best and easy option for me to implement the algorythm I've described using current implementation of Spring Integration ?
Thanks all !


Reply With Quote
