问题
So I am creating concurrent consumers to a topic i.e. multiple listeners. I am configuring them to be durable.
@Bean
public DefaultMessageListenerContainer listenerContainers() {
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
container.setConnectionFactory(connectionFactory());
container.setDestinationName(COMMENT_QUEUE);
container.setPubSubDomain(true);
container.setSessionTransacted(true);
container.setConcurrentConsumers(2);
container.setSubscriptionDurable(true);
container.setMessageListener(datafileSubscriber);
container.start();
return container;
}
I am thinking the use case scenario of durable consumer is
I have a process which publishes message and the message is pickedup by listeners. I was thinking if someone stopped the process and I restarted it again, I wouldnt lose messages and their processing because f durable consumers.
Is that right?
I will not lose messages because the messages are in KahaDB and after the process is restarted it will resend the messages which havent been completely processed to listeners because they are durable. Is this right explanation ?
回答1:
That is correct; topic subscriptions are not durable by default; only subscribers actively consuming get messages. New consumers only get new messages published while subscribed.
A durable consumer acts more like a queue; the broker keeps track of them and keeps messages around until all such consumers have received them.
The subscription only becomes durable when it is established. If the broker doesn't know about it, messages won't be retained. Hence it's important to establish your durable subscriptions before publishing any messages.
来源:https://stackoverflow.com/questions/46490934/use-case-scenario-of-durable-listeners-consumers