Can a JMS subscriber client ID be migrated across hosts?
I have a task that has a durable subscriber on a JMS topic and I need to be able to move this task from one host to another.
The task has set its Client ID using:
TopicConnection.setClientID("MyClient");
and:
TopicSession.createDurableSubscriber(Topic, "durable");
For the relevant instances of TopicConnection, TopicSession and Topic. I'm using client acknowledgement and every message is acknowledged upon successful handling (there were no errors in the example run I posted below).
The task will always have the same Client ID (combination of "MyClient" and "durable").
However, it appears as if this same Client ID is treated as separate for each host.
So I get the following scenario:
- Host A is running the subscriber.
- Messages 1-10 are sent.
- Host A receives messages 1-10 and shuts down it's subscriber (closing the connection)
- Messages 11-20 are sent.
- Host B sets up a subscriber with (apparently) the same Client ID
- Messages 21-30 are sent.
- Host B receives messages 开发者_开发百科11-30 (and often a few prior messages, seemingly at random)
- Host B shuts it's subscriber down
- Host A sets up it's subscriber again
- Host A receives messages 11-30
Am I right in thinking that the host identity is somehow being incorporated into the Client ID under the hood? And is there a way of stopping this happen.
I'm using SwiftMQ, in case this is behaviour is peculiar to that solution.
my understanding of how durable subscribers work (assuming everything is shutdown correctly in step 8.) is the same as yours (this seems like a bug). i have never seen anything indicating that durable subscriptions (or any jms subscriptions for that matter) are tied to a specific host. this would seem to break any attempt at building a robust system (i.e. if the original host crashes, you are stuck).
Ok, we've figured out why this is happening.
Each server in our cluster maintains its own JMS router. In SwiftMQ (if not all JMS implementations) durable subscriptions are location dependant. As each router maintains its own list of durable subscriptions, two durable subscriptions on separate routers will be managed separately, even if they have the same Client ID.
精彩评论