如何选择Topic Vs Queue [英] How to select Topic Vs Queue

查看:216
本文介绍了如何选择Topic Vs Queue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们设计应用程序如何选择Topic / Queue类型实现。

我知道,

a)如果多个消费者使用消息,然后使用Topic

b)如果只有一个消费者使用队列



请提供更多的点需要考虑吗?

例如,并发,消息持久性,负载平衡等等。



感谢。

Rw



我们有一个Java EE应用程序,我们对保险报价进行评级。我们有一个RatingIn队列和一个RatingOut队列。所有我们的客户写入RatingIn队列并从RatingOut队列中读取。



多个客户端访问同一队列以读取的技巧是使用消息头中的correlationID。使它对客户端是唯一的,他们只是拿起他们独特的消息。我们做的是将客户端中的correlationID设置为RatingIn绑定的消息。然后,服务器拾取属性并写入消息,将其写回RatingOut。这为独特的客户保留了独特的消息,但不需要300多个队列(根据我们的应用服务器管理员数量,这些队列很快就会变得无法管理)。



认为它与发布方法更有关系。如果您希望发布仅适用于一个消费者的消息,请使用队列。如果您希望发布针对多个消费者的消息,但不生成大量消息(您也可能不知道您要发布多少个消费者),请使用主题。


When we design the application how to select Topic/Queue type implementation.
I am aware of,
a) If more than one consumer use the message then use Topic
b) If only one consumer then use Queue

Please provide any more points need to be considered?
For example, concurrency, message persistence, load balancing, anything else?

Thanks.
Rw

解决方案

That's not entirely true about if only one Consumer use a Queue.

We have a Java EE app where we rate insurance quotes. We have a RatingIn queue and a RatingOut queue. All our clients write to the RatingIn Queue and read from the RatingOut Queue. And we have probably near 300+ clients.

The trick with multiple clients accessing the same Queue to read from is using the correlationID in the message headers. Make it unique to the client and they only pick up their unique message. What we do is set this correlationID in the client to the message bound for RatingIn. Then the server picks up the property and writes to the message that it writes back to RatingOut. This preserves unique messages for unique clients, but without the need for 300+ queues (which would quickly become unmanageable at our company given our number of app server admins).

I think it has more to do with the publication method. If you wish to publish a message meant for only one Consumer, use a Queue. If you wish to publish a message meant for multiple Consumers, but without generating a ton of messages (and you may also not know how many Consumers you have to publish for), then use a Topic.

这篇关于如何选择Topic Vs Queue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆