How to select Topic Vs Queue

泄露秘密 提交于 2019-12-04 16:41:14
Chris Aldrich

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!