Sobes.tech
Junior — Middle

What are the main differences between a topic and a queue in a messaging system?

sobes.tech AI

Answer from AI

In messaging systems (e.g., JMS), the main difference between a topic and a queue lies in the message delivery model:

  • Queue implements the point-to-point model. A message sent to a queue will be received by only one consumer. If multiple consumers listen to the queue, each message is delivered to exactly one of them. This is convenient for task distribution among workers.

  • Topic implements the publish-subscribe model. A message published to a topic is delivered to all subscribers who are active at the time of publication. This is suitable for broadcasting events or notifications to multiple recipients.

Example:

  • In an order queue, each order is processed by one worker.
  • In a news topic, all subscribers receive each new message.

Thus, the choice depends on the task: either delivery to a single consumer (queue) or to many (topic).