How do I do async RPC calls with RabbitMq

I'm trying to do a RestApi (asp.net core) that calls the backend (C#) through RabbitMq. To handle many requests I will need to call the backend asynchronously.

For me the example code from rabbitmq seem not to be thread-safe because it dequeues messages until the one with the correct correlation id is returned. All others will be ignored. (link: https://www.rabbitmq.com/tutorials/tutorial-six-dotnet.html )

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

I'm thinking in the following possibilities:


Possibility 1:

I could use the SimpleRpcClient and create for each request a own instance. This will cause that for each request a new queue to reply gets created.

Possibility 2:

Create a own RPC client that creates one reply queue (probably per request type) and returns the right response to the right request depending on the correlation id.


What is the best practice to make multiple calls asynchronous? Are there already implementations for the second possibility or do I need to implement this by myself?


  • Design a job queue, Push job to queue from generator and forget so that job generator remains responsive
  • Have multiple workers equal to number of available CPU threads (for optimized performance) to process jobs
  • Each worker to deque job from main queue and put it with results along in new queue.
  • Keep features for
  • Not to process *too old** jobs.
  • Terminate long running jobs.
  • Pick high priority jobs first.
  • If permitted design remote job runner nodes
  • 链接地址: http://www.djcxy.com/p/61230.html

    上一篇: 请求RabbitMQ NodeJs

    下一篇: 我如何使用RabbitMq进行异步RPC调用