RabbitMQ RPC tutorial query

I was going through the tutorial shared by RabbitMQ here

I am assuming that the client code below

  while (true)
        {
            var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
            if (ea.BasicProperties.CorrelationId == corrId)
            {
                return Encoding.UTF8.GetString(ea.Body);
            }
        }

Would receive all messages on the queue and will unnecessarily iterate through messages not designated for it. Is their anyway we can avoid it ie we can modify the client to only receive the messages intended for it only.

The basic work that i intend to achieve through RabbitMQ is Request-Response pattern where a request would be received by web-service which will send data in a queue the data object would have a unique reference number . This would be received by an asynchronous tcp-client which will send data on a tcp/ip layer based on message it had received.

On receiving reply from the asynchronous channel of tcp/ip the channel would parse the data and respond back on the queue with the corresponding request reference number.

The RPC approach is well suited for it but the client code shared have this shortcoming would appreciate feedback on it.


Actually I didn't understand well your aim, but when you create an RPC model, you have to create an “reply queue”, this queue is bound only to the client. It means that you will receive back only the client messages, and not all messages. Since the Rabbitmq RPC model is asynchronous you can execute more than one request without wait the responses and replies could not have the same publish order.

The correlation id is necessary to map your client requests with the replies, so there are not " unnecessarily " messages

hope it helps

链接地址: http://www.djcxy.com/p/61222.html

上一篇: 处理rpc请求的最佳设计模式是什么?

下一篇: RabbitMQ RPC教程查询