We are shutting down cometd client in the below fashion. Is there a way we can ensure that all the pending events are published ? Sometimes we are seeing issue where some of the events send just before triggering shutdown is lost.
public void shutdown() {
try {
if (bayeuxClient != null) {
bayeuxClient.getChannel(getChannelInfo()).unsubscribe();
bayeuxClient.disconnect(10000L);
bayeuxClient.waitFor(10000L, BayeuxClient.State.DISCONNECTED);
}
if (client != null) {
client.stop();
}
} catch (Exception e) {
log.warn(e.getMessage());
} finally {
client = null;
bayeuxClient = null;
}
}
If you are publishing and disconnecting from concurrent threads, there is a possibility that the disconnect overtakes the publish.
In general, this issue must be resolved at the application level, i.e. it is the application that should coordinate the last publish and the disconnect.
You have the following choices:
Use Batching
Batching ensures ordering:
Use MessageListener
Use a message listener from the
publish()so that you are notified of when the last publish is complete, and then you can disconnect: