简体   繁体   English

JMS主题与队列 - 意图

[英]JMS Topic vs Queue - Intent

I am trying to understand the use case of using Queue. 我试图了解使用Queue的用例。

My understanding: Queue means one-to-one. 我的理解:队列意味着一对一。 The only use case(if not rare, very few) would be: Message is intended for only one consume. 唯一的用例(如果不罕见,很少)将是:消息仅用于一次消费。

But even in those cases, I may want to use Topic (just to be future safe). 但即使在这些情况下,我也可能想要使用Topic(只是为了将来安全)。 The only extra caution would be to make subscriptions durable. 唯一需要特别注意的是使订阅持久。 Or, in special situations, I would use bridging / dispatcher mechanism. 或者,在特殊情况下,我会使用桥接/调度机制。

Given above, I would always (or in most cases) want to publish to a topic. 鉴于上述情况,我总是(或在大多数情况下)想要发布主题。 Subscriber can be either durable topic(s) or dispatched queue(s). 订阅者可以是持久主题或分派队列。

Please let me know what I am missing here or I am missing the original intent? 请让我知道我在这里缺少什么,或者我错过了原来的意图?

The design requirements on when to use queues are simple if you think in terms of real-world examples: 如果您根据实际示例考虑,何时使用队列的设计要求很简单:

  • Submit online order (exactly-once processing to avoid charging credit card twice) 提交在线订单(完全一次处理,以避免两次信用卡收费)
  • Private peer-to-peer chat (exactly one receiver for each message) 私人点对点聊天(每个消息只有一个接收者)
  • Parallel task distribution (distribute tasks amongst many workers in a networked system) 并行任务分配(在网络系统中的许多工作人员之间分配任务)

...and examples for when to use topics... ...以及何时使用主题的示例......

  • News broadcast to multiple subscribers; 新闻广播给多个用户; notification service, stock ticker, etc. 通知服务,股票代码等
  • Email client (unique durable subscriber; you still get emails when you're disconnected) 电子邮件客户端(独特的持久订阅者;当您断开连接时仍然会收到电子邮件)

You said... 你说...

But even in those cases, I may want to use Topic (just to be future safe). 但即使在这些情况下,我也可能想要使用Topic(只是为了将来安全)。 The only extra case I would have to do is to make (each) subscription durable. 我要做的唯一额外情况是使(每个)订阅持久。 Or, I special situations, I would use bridging / dispatcher mechanism. 或者,我特殊情况,我会使用桥接/调度机制。

You're over-engineering the design. 你过度设计了这个设计。 It's true, you can achieve exactly-once processing using a topic and durable subscriber, but you'd be limited to a single durable subscriber; 确实,您可以使用主题和持久订阅者完成一次处理,但您只能使用一个持久的订阅者; the moment you start another subscriber for that topic, you'll get duplicate processing for the same message, not to mention, a single durable subscriber is hardly a solution that scales; 当您为该主题启动另一个订阅者时,您将获得对同一消息的重复处理,更不用说,单个持久订阅者几乎不是可扩展的解决方案; it would be a bottleneck in your system for sure. 它肯定会成为你系统的瓶颈。 With a queue, you can deploy 1000 receivers on 100 nodes for the same queue, and you'd still get exactly-once processing for a single message. 使用队列,您可以在同一队列的100个节点上部署1000个接收器,并且您仍然可以对单个消息进行一次性处理。

You said... 你说...

Give above, I would always (or in most cases) want to publish to a topic. 在上面,我总是(或在大多数情况下)想要发布到一个主题。 Subscriber can be either durable topic(s) or dispatched queue(s). 订阅者可以是持久主题或分派队列。

Using a dispatched queue with a topic subscriber is sort of redundant. 使用带有主题订阅者的调度队列有点多余。 You basically get asynchronous dispatching when using queues, so why not just use a queue?...no reason to put a topic in front of it. 在使用队列时,你基本上可以进行异步调度,那么为什么不使用队列呢?...没有理由在它前面放置一个主题。

You are probably missing that both queues and topics can have multiple subscribers. 您可能错过了队列和主题都可以拥有多个订阅者。 A queue will deliver the message to one of potentially many subscribers, while a topic will deliver the message to all subscribers. 队列将消息传递给潜在的许多订户之一,而主题将消息传递给所有订户。

If you in your case is sure that there is only one subscriber, then a queue subscriber and a durable topic subscriber will behave similarly. 如果您确实只有一个订阅者,那么队列订阅者和持久主题订阅者的行为将类似。 I would rather look at such a scenario as a "special case". 我宁愿把这种情景视为“特例”。

Queues and Topics in JMS represent two different models - point to point and publish/subscribe. JMS中的队列和主题代表两种不同的模型 - 点对点和发布/订阅。 Topics will keep a message until all clients receive them, all subscribers handling them. 主题将保留消息,直到所有客户端都收到它们,所有订阅者都处理它们。 Queues will wait for the first consumer to pull the message, and consider it read at that point. 队列将等待第一个消费者提取消息,并考虑在那时读取消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM