I have configured a pub-sub channel, and would like to have a single dedicated thread per subscriber (each subscriber is a service-activator.) Is it possible?
Thanks,
Khoa
I have configured a pub-sub channel, and would like to have a single dedicated thread per subscriber (each subscriber is a service-activator.) Is it possible?
Thanks,
Khoa
Sure. It sounds like you just want to add a reference to an Executor instance via the publish-subscribe-channel element's "task-executor" reference. You can even use Spring's "task" namespace to configure the Executor. Details are here: http://static.springsource.org/sprin...task-namespace
Mark Fisher
Spring Integration Lead
SpringSource, a division of VMware
http://www.springsource.com
http://www.springsource.org/spring-integration
http://blog.springsource.com/main/author/markf
Thanks Mark for your inputs. However, with the following config:
isn't it true that each service-activator may be running concurrently and not single-threaded? I would like to pin a single thread to each service-activator since the service-activator implementation is not thread-safe.Code:<publish-subscribe-channel id="dataChannel" task-executer="workers"/> <task:executor id="workers" pool-size="5"/> <service-activator id="a" input-channel="dataChannel" .../> <service-activator id="b" input-channel="dataChannel" .../> ...
Thanks,
Khoa
Well, if you really want to have exactly one thread per service activator, then you should probably use a simple <channel> as the input of each service-activator and then add a <dispatcher> sub-element to each of those that has a task-executor reference that is a single threaded executor. To connect all of those to a single publish-subscribe-channel you could use <bridge> elements. Simpler, but probably overly serialized, you could just use a single-threaded executor on the publish-subscribe-channel (overly serialized in this case meaning that you would not even have concurrent invocation of the different service-activator instances).
Personally, I would really try to make the service thread safe instead, even if that means adding 'synchronized' blocks to avoid concurrency at that level.
Mark Fisher
Spring Integration Lead
SpringSource, a division of VMware
http://www.springsource.com
http://www.springsource.org/spring-integration
http://blog.springsource.com/main/author/markf
Thanks again. I will try the <bridge> option first since it requires no code changes :-) Making it thread-safe will be phase 2...
Regards,
Khoa