Implementing Publish Only Bus in MassTransit v3 with C# and RabbitMQ
<p>I am trying to implement a publish only bus in MassTransit v3 with C# and RabbitMQ where the bus has no consumer. The concept is messages will be published and queued, then a separate microservice will consume messages from the queue. Looking at <a href="https://stackoverflow.com/questions/33633045/mass-transit-no-consumer#answer-33636960">this SO answer</a>, receive endpoints must be specified so that messages are actually queued. However this appears to <a href="http://docs.masstransit-project.com/en/latest/configuration/gotchas.html#send-only-bus" rel="nofollow noreferrer">contradict the common gotchas in the MassTransit docs</a>, which states <code>If you need to only send or publish messages, don’t create any receive endpoints</code>.</p>

<p>Here is some sample code:</p>

<pre><code>    public class Program
    {
        static void Main(string[] args)
        {
            var bus = BusConfigurator.ConfigureBus();

            bus.Start();

            bus.Publish&lt;IItemToQueue&gt;(new ItemToQueue { Text = "Hello World" }).Wait();

            Console.ReadKey();

            bus.Stop();
        }
    }

    public static class BusConfigurator
    {
        public static IBusControl ConfigureBus()
        {
            var bus = Bus.Factory.CreateUsingRabbitMq(cfg =&gt;
            {
                var host = cfg.Host(new Uri("rabbitmq://localhost/"), hst =&gt;
                {
                    hst.Username("guest");
                    hst.Password("guest");
                });

                cfg.ReceiveEndpoint(host, "queuename", e =&gt;
                {
                    e.Consumer&lt;MyConsumer&gt;();
                });
            });

            return bus;
        }
    }

    public interface IItemToQueue
    {
        string Text { get; set; }
    }

    public class ItemToQueue : IItemToQueue
    {
        public string Text { get; set; }
    }

    public class MyConsumer : IConsumer&lt;IItemToQueue&gt;
    {
        public async Task Consume(ConsumeContext&lt;IItemToQueue&gt; context)
        {
            await Console.Out.WriteLineAsync(context.Message.Text);
        }
    }
</code></pre>

<p>In this sample, I receive the message in the RabbitMQ queue as expected, and this is consumed by <code>MyConsumer</code> which writes Hello World to the console and the message is then removed from the Queue.</p>

<p>However, when I remove the following code from the above and re-run the sample:</p>

<pre><code>cfg.ReceiveEndpoint(host, RabbitMqConstants.ValidationQueue, e =&gt;
{
    e.Consumer&lt;MyConsumer&gt;();
}); 
</code></pre>

<p>A temporary queue is created (with a generated name) and the message never seems to be placed into the temporary queue. This queue is then removed when the bus is stopped.</p>

<p>The problem I have is with a ReceiveEndpoint specified, the messages will be consumed and removed from the queue in the publisher program (meaning the consumer microservice wouldn't process queued items). Without a RecieveEndpoint specified, a temporary queue is used (and the consumer microservice would not know the name of this temporary queue), the message never seems to get queued and the queue is deleted when the bus is stopped which wouldn't be good if the program went down. </p>

<p>There is <a href="http://docs.masstransit-project.com/en/latest/patterns/sendonly.html" rel="nofollow noreferrer">an example of a send only bus in the MassTransit docs</a> but it is pretty basic so I was wondering if anyone had any suggestions?</p>