-
Aug 22nd, 2010, 12:46 AM
#1
Cloning payloads across subscribers when using publish-subscribe channel
Hi,
I've noticed that when messages are dispatched across several subscribers (on a publish-subscribe channel), the same payload instance is being shared across all messages. This means that if the payload is a collection, modifying the collection on one subscriber might affect a different subscriber working on the same collection.
What is the best practice for cloning the payload when using a publish-subscribe channel?
Thanks!
-
Aug 25th, 2010, 10:35 PM
#2
There is nothing specific in SI nor there is any recommendation that we can give. I think its on the per use case basis and is up to you - the developer.
The main issue as I am sure you'd agree is concurrency but based on the load and other criteria it could be handled differently (synchronization vs cloning, etc. . .).
The only thing framework handles for you is what is in our control and that is a message. Every time a message makes a hop its a new instance of the message built form the combination of values form old message plus new stuff.
-
Aug 26th, 2010, 01:29 AM
#3
Thanks Oleg,
I've kind of figured that out. I was hoping that, considering the fact that my use case is not that uncommon, there is already some "magic" solution somewhere. For example, a pub-subscribe channel could be configured to be a "cloning-channel" which clones the payload of its messages (allowing the developer to only write the cloning logic and defining the name of the cloning-method).
But I understand that this is not in the scope of the spring-integration framework, so as you said - it's a concurrency problem and can be dealt with in the traditional ways.
Thanks again.
-
Aug 26th, 2010, 03:19 PM
#4
If you're going to share payloads with multiple threads, make them immutable. There are other ways out, but they're harder.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules