can Bunny filter incoming message by correlation id?

15 views
Skip to first unread message

Jack Xu

unread,
Nov 19, 2018, 6:00:35 PM11/19/18
to Ruby RabbitMQ libraries
Hi group, 

I have been trying to get RPC style communication working using the correlation id approach. I see there is a similar example provided, however, the reply-to queue is set to be a random name that is unique to the request, i.e. the queue is only expecting one response and can safely disregard any other messages. 

Question: what should I do if I would like the reply-to queue to be static and all the responses will go to the same queue? Is there a way, like in IBMMQ api, where you can filter messages in queue by a correlation id? 

Thanks!
Jack 

Michael Klishin

unread,
Nov 19, 2018, 6:08:30 PM11/19/18
to Ruby RabbitMQ libraries
Correlation ID is merely a field that helps request/response clients to identify what request a response is for [1].

Message distribution in RabbitMQ happens at routing time so you can try e.g. the consistent hash exchange but I'm not sure
how correlation ID is related. Can you elaborate a bit?

Jack Xu

unread,
Nov 19, 2018, 8:52:39 PM11/19/18
to ruby...@googlegroups.com
Hi Michael, 

Thanks for getting back to me!

I get correlation id field is nothing special. Let me elaborate my question: 

As far as I know, there are two ways to implement correlation id style request/response communication with rabbitmq: 
1. hidden unique queue for each request: an example is in https://github.com/rabbitmq/rabbitmq-tutorials/blob/master/ruby/rpc_client.rb, to which you contributed. 
2. same queue for all the responses: in this case, instead of specifying empty queue name to use a random unique queue in the previous approach, the Reply-to queue name is the fixed and all responses for requests end up in there. In order to only get the response for the particular request, because all the responses come into the same queue, I will need to filter them by correlation id to get the response. 

It perhaps can look something like: response_queue.pop(correlation_id: my_correl_id) 

This type of filtering is implemented by IBM MQ, see MQMO_MATCH_CORREL_ID in MatchOptions as documented on https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_8.0.0/com.ibm.mq.ref.dev.doc/q096750_.htm

Thoughts? 
Jack

--
Bunny: http://rubybunny.info
March Hare: http://rubymarchhare.info
 
IRC: #rabbitmq on irc.freenode.net
 
Post to the group: ruby...@googlegroups.com | unsubscribe: ruby-amqp+...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Ruby RabbitMQ libraries" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-amqp+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jack Xu

unread,
Dec 2, 2018, 7:31:44 PM12/2/18
to ruby...@googlegroups.com
I haven't seen an update on this. perhaps i missed it? 

Michael Klishin

unread,
Dec 3, 2018, 11:42:50 AM12/3/18
to ruby...@googlegroups.com
You cannot filter messages in queues or query them. You can consume, decide and potentially requeue
but it's inefficient. My advice is to architect your system without the need for such filtering or "offload" the filtering part
to a data store that supports querying (e.g. PostgreSQL).
--
MK

Staff Software Engineer, Pivotal/RabbitMQ
Reply all
Reply to author
Forward
0 new messages