Skip to content
On this page

Using Rabbit MQ


Wolverine uses the Rabbit MQ .NET Client to connect to Rabbit MQ.


All the code samples in this section are from the Ping/Pong with Rabbit MQ sample project.

To use RabbitMQ as a transport with Wolverine, first install the Wolverine.RabbitMQ library via nuget to your project. Behind the scenes, this package uses the RabbitMQ C# Client to both send and receive messages from RabbitMQ.

return await Host.CreateDefaultBuilder(args)
    .UseWolverine(opts =>
        // Listen for messages coming into the pongs queue

            // This won't be necessary by the time Wolverine goes 2.0
            // but for now, I've got to help Wolverine out a little bit

        // Publish messages to the pings queue

        // Configure Rabbit MQ connection properties programmatically
        // against a ConnectionFactory
        opts.UseRabbitMq(rabbit =>
                // Using a local installation of Rabbit MQ
                // via a running Docker image
                rabbit.HostName = "localhost";
            // Directs Wolverine to build any declared queues, exchanges, or
            // bindings with the Rabbit MQ broker as part of bootstrapping time

        // Or you can use this functionality to set up *all* known
        // Wolverine (or Marten) related resources on application startup

        // This will send ping messages on a continuous
        // loop

snippet source | anchor

See the Rabbit MQ .NET Client documentation for more information about configuring the ConnectionFactory to connect to Rabbit MQ.

Disable Rabbit MQ Reply Queues

By default, Wolverine creates an in memory queue in the Rabbit MQ broker for each individual node that is used by Wolverine for request/reply invocations (IMessageBus.InvokeAsync<T>() when used remotely). Great, but if your process does not have permissions with your Rabbit MQ broker to create queues, you may encounter errors. Not to worry, you can disable that Wolverine system queue creation with:

using var host = await Host.CreateDefaultBuilder()
    .UseWolverine(opts =>
        // *A* way to configure Rabbit MQ using their Uri schema
        // documented here:
        opts.UseRabbitMq(new Uri("amqp://localhost"))
            // Stop Wolverine from trying to create a reply queue
            // for this node if your process does not have permission to
            // do so against your Rabbit MQ broker


        // Set up a listener for a queue, but also
        // fine-tune the queue characteristics if Wolverine
        // will be governing the queue setup
        opts.ListenToRabbitQueue("incoming2", q =>
            q.PurgeOnStartup = true;

snippet source | anchor

Of course, doing so means that you will not be able to do request/reply through Rabbit MQ with your Wolverine application.

Released under the MIT License.