JMS Topic vs Queues

前端 未结 9 2093
广开言路
广开言路 2020-12-04 04:48

I was wondering what is the difference between a JMS Queue and JMS Topic.

ActiveMQ page says

Topics

In JMS a Topic implements <

相关标签:
9条回答
  • 2020-12-04 05:20

    It is simple as that:

    Queues = Insert > Withdraw (send to single subscriber) 1:1

    Topics = Insert > Broadcast (send to all subscribers) 1:n

    0 讨论(0)
  • 2020-12-04 05:21

    A JMS topic is the type of destination in a 1-to-many model of distribution. The same published message is received by all consuming subscribers. You can also call this the 'broadcast' model. You can think of a topic as the equivalent of a Subject in an Observer design pattern for distributed computing. Some JMS providers efficiently choose to implement this as UDP instead of TCP. For topic's the message delivery is 'fire-and-forget' - if no one listens, the message just disappears. If that's not what you want, you can use 'durable subscriptions'.

    A JMS queue is a 1-to-1 destination of messages. The message is received by only one of the consuming receivers (please note: consistently using subscribers for 'topic client's and receivers for queue client's avoids confusion). Messages sent to a queue are stored on disk or memory until someone picks it up or it expires. So queues (and durable subscriptions) need some active storage management, you need to think about slow consumers.

    In most environments, I would argue, topics are the better choice because you can always add additional components without having to change the architecture. Added components could be monitoring, logging, analytics, etc. You never know at the beginning of the project what the requirements will be like in 1 year, 5 years, 10 years. Change is inevitable, embrace it :-)

    0 讨论(0)
  • 2020-12-04 05:28

    Queue is JMS managed object used for holding messages waiting for subscribers to consume. When all subscribers consumed the message , message will be removed from queue.

    Topic is that all subscribers to a topic receive the same message when the message is published.

    0 讨论(0)
提交回复
热议问题