Use case scenario of durable listeners/consumers

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 05:51:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!