-
|
We have a Java application that consumes messages from NATS using the code below with the doConsume=true flag enabled. The application monitors whether the NATS cluster fails over from AWS use1 region to euw1 region through a monitoring thread. Before calling forceReconnect(), do we need to explicitly call unsubscribe() to clean up the old use1 subscription? Since NATS push consumer load-balances message distribution among all subscriptions, if during the failover migration period, the old use1 subscription and the new euw1 migration subscription coexist (using the same durable consumer name), messages will be scattered between the two subscriptions, causing the migration subscription to fail to receive all messages. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
No. Subscriptions will be re-made. Can you experiment to see what happens? What are your results? I don't understand the monitorIpChange code. If the connection detects a disconnection, it will automatically reconnect, unless you have turned that ability off in the Options. You should look into simplified consuming instead of push based consuming. https://github.com/nats-io/nats.java/tree/main/src/examples/java/io/nats/examples/jetstream/simple |
Beta Was this translation helpful? Give feedback.
-
|
1. Pull consumers automatically balance the same as push queue subscriptions without any extra work. Simplification uses pull. Reconnects go to the same cluster they were already connected too, so I'm not sure what a force reconnect buys you, unless you provided your own server pool implementation to force connecting to another cluster. If you do reconnect to another cluster, and the stream is not mirrored or the cluster is not part of a super cluster, subscription won't matter as the stream won't exist. I still don't understand why you need to reconnect if there is no connection loss. When the publishers comes back on line, the consumer will start getting messages again. And if it has consumed less messages than are already in the stream if publishing is very fast, then this gives consumers time to catch up. In order to ensure processing of all messages in a stream for a given consumer, you must use the ack feature. If a message is not acked within the ack wait timeframe, it will be redelivered. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @scottf |
Beta Was this translation helpful? Give feedback.
1. Pull consumers automatically balance the same as push queue subscriptions without any extra work. Simplification uses pull.
2. Any reconnect, including force reconnect, subscriptions are re-established
Reconnects go to the same cluster they were already connected too, so I'm not sure what a force reconnect buys you, unless you provided your own server pool implementation to force connecting to another cluster.
If you do reconnect to another cluster, and the stream is not mirrored or the cluster is not part of a super cluster, subscription won't matter as the stream won't exist.
I still don't understand why you need to reconnect if there is no connection loss. When the publishers comes …