title: How do I do async RPC calls with RabbitMq
body: <p>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. </p>
  
  <p>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: <a href="https://www.rabbitmq.com/tutorials/tutorial-six-dotnet.html" rel="noreferrer">https://www.rabbitmq.com/tutorials/tutorial-six-dotnet.html</a> )</p>
  
  <pre><code>  while(true)
    {
        var ea = (BasicDeliverEventArgs)consumer.Queue.Dequeue();
        if(ea.BasicProperties.CorrelationId == corrId)
        {
            return Encoding.UTF8.GetString(ea.Body);
        }
    }
  </code></pre>
  
  <p>I'm thinking in the following possibilities:</p>
  
  <hr>
  
  <h2>Possibility 1:</h2>
  
  <p>I could use the <a href="https://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v2.8.6/rabbitmq-dotnet-client-2.8.6-client-htmldoc/html/type-RabbitMQ.Client.MessagePatterns.SimpleRpcClient.html" rel="noreferrer">SimpleRpcClient</a> and create for each request a own instance. This will cause that for each request a new queue to reply gets created.</p>
  
  <h2>Possibility 2:</h2>
  
  <p>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.</p>
  
  <hr>
  
  <p>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?</p>