Search code examples
rabbitmqjmsmessage-queueamqpstomp

what happens when message published on queue with no Subscriber?


this was asked to me in an interview.

what happens when message published on queue with no Subscriber at 10 AM? and a subscriber with proper filter subscribes at 10.02 AM to same Queue. Does the message gets delivered when a subscriber subscribes after the message has reached to the broker (I mean does it store in the memory until it finds the subscriber)? what is default behavior? also is it different in JMS, STOMP and AMQP standerds?


Solution

  • In AMQP brokers, messages are either deliver to consumers that are subscribing to queues, or when consumers fetch/pull messages from queues on demand. Messages will stay in the queue be default even if no subscriber is active at the moment. A message will be stored on disk if it's a persistent message and in memory if not persistent. https://www.rabbitmq.com/tutorials/amqp-concepts.html

    STOMP: The RabbitMQ STOMP adapter supports a number of different destination types. Messages sent when no subscriber exists will be queued until a subscriber connects to the queue (while a topic will drop messages when there are no connected subscribers). https://www.rabbitmq.com/stomp.html

    JMS: JMS is an API, it doesn't use any protocol. AMQP on other hand is a protocol between a messaging client and messaging server. A JMS client can use AMQP as the protocol to communicate with the messaging server. (check this article for more information about the subject https://spring.io/understanding/AMQP)

    However, messages sent to a queue remain in the queue until the message consumer for that queue consumes them. http://docs.oracle.com/javaee/6/tutorial/doc/bnceh.html and https://en.wikipedia.org/wiki/Java_Message_Service