title: Connection between RabbitMQ and MassTransit
body: <p>Okay so I have the following problem, this is just a basic test-program but I'm already struggling. I'm very new to this and haven't found a similar scenario yet.</p>
  
  <p>Basically, I need to publish messages to a specific queue (more down the line, but the point is we need a fixed topology) and as far as I understand things, I can't do that with MassTransit.</p>
  
  <p>My idea now was to publish messages to a queue using bare RabbitMQ and then reading from that Queue with MassTransit. </p>
  
  <p>So I got 2 very basic console applications now with TestPublisher being the publisher using RabbitMQ only and TestSubscriber being the consumer using MassTransit. </p>
  
  <p><strong>TestPublisher:</strong></p>
  
  <p><em>Program.cs</em></p>
  
  <pre><code>using System;
  using RabbitMQ.Client;
  using System.Text;
  using TestPublisher;
  
  class Program
  {
      public static void Main()
      {
          var factory = new ConnectionFactory() { HostName = "localhost", VirtualHost = "testvhost" };
          using (var connection = factory.CreateConnection())
          using (var channel = connection.CreateModel())
          {
  
  
              var message = new TestMessage(){ message = "Test"};
              var body = Encoding.UTF8.GetBytes(message.message);
  
              channel.BasicPublish(exchange: "MTQueue", routingKey: "MTQueue", basicProperties: null, body: body);
              Console.WriteLine(" [x] Sent {0}", message);
          }
  
          Console.WriteLine(" Press [enter] to exit.");
          Console.ReadLine();
      }
  }
  </code></pre>
  
  <p><em>TestMessage.cs</em></p>
  
  <pre><code>using Contracts;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace TestPublisher
  {
      class TestMessage : MessageDelivery
      {
          public string message { get; set; }
  
      }
  }
  </code></pre>
  
  <p><strong>TestSubscriber</strong></p>
  
  <p><em>Program.cs</em></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using MassTransit;
  using MassTransit.Log4NetIntegration.Logging;
  
  namespace TestSubscriber
  {
      class Program
      {
          static void Main(string[] args)
          {
              Log4NetLogger.Use();
              var bus = Bus.Factory.CreateUsingRabbitMq(x =&gt;
              {
                  var host = x.Host(new Uri("rabbitmq://localhost/testvhost/"), h =&gt; { });
                  x.ReceiveEndpoint(host, "MTQueue", e =&gt; e.Consumer&lt;TestMessageConsumer&gt;());
              });
              bus.Start();
              Console.ReadKey();
              bus.Stop();
  
          }
      }
  }
  </code></pre>
  
  <p><em>TestMessageConsumer.cs</em></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Contracts;
  using MassTransit;
  
  namespace TestSubscriber
  {
      class TestMessageConsumer : IConsumer&lt;MessageDelivery&gt;
      {
          public Task Consume(ConsumeContext&lt;MessageDelivery&gt; context)
          {
              Console.Write("TEXT: " + context.Message);
              Console.Write(" VERARBEITET: " + DateTime.Now);
              Console.WriteLine(" (" + System.Threading.Thread.CurrentThread.ManagedThreadId + ")");
              return Task.FromResult(0);
          }
      }
  }
  </code></pre>
  
  <p><strong>Contracts</strong></p>
  
  <p><em>Contracts.cs</em></p>
  
  <pre><code>using System;
  
  namespace Contracts
  {
      public interface MessageDelivery
      {
          string message { get; }
      }
  }
  </code></pre>
  
  <p>I can publish to the queue with TestPublisher without problems, the message will be in the correct queue, using the RabbitMQ Management interface to verify.</p>
  
  <p>My problem now, as RabbitMQ will only let me publish byte-arrays with BasicPublish, is that I can't get the message from the queue with TestSubscriber, as the consumer expects a message of the type MessageDelivery and won't let me configure the ConsumeContext or IConsumer to listen for byte[]</p>
  
  <p>I'm really stuck here and can't find a solution, neither on RabbitMQ side nor on the MassTransit side.</p>