Skip to content

Shuttle.Hopper.RabbitMQ

This RabbitMQ implementation follows the at-least-once delivery mechanism supported by Shuttle.Hopper.

If necessary you may want to use an outbox for a store-and-forward solution. By using a transactional outbox such as the Shuttle.Hopper.SqlServer.Queue implementation you could roll back sending of messages on failure.

Installation

bash
dotnet add package Shuttle.Hopper.RabbitMQ

If you need to install RabbitMQ you can follow these instructions.

Configuration

The URI structure is rabbitmq://configuration-name/queue-name.

c#
services.AddHopper(builder =>
{
    builder.UseRabbitMQ(rabbitMQBuilder =>
    {
        rabbitMQBuilder.AddOptions("local", new RabbitMQOptions
        {
            ConnectionFactory = new RabbitMQ.Client.ConnectionFactory(),
            Host = "127.0.0.1",
            VirtualHost = "/",
            Port = -1,
            Username = "shuttle",
            Password = "shuttle!",
            PrefetchCount = 25,
            QueueTimeout = TimeSpan.FromSeconds(1),
            RequestedHeartbeat = TimeSpan.FromSeconds(30),
            ConnectionCloseTimeout = TimeSpan.FromSeconds(1),
            OperationRetryCount = 3,
            Priority = 0,
            Persistent = true,
            Durable = true
        });
    });
});

The default JSON settings structure is as follows:

json
{
  "Shuttle": {
    "RabbitMQ": {
      "local": {
        "Host": "127.0.0.1",
        "VirtualHost": "/",
        "Port": -1,
        "Username": "shuttle",
        "Password": "shuttle!",
        "PrefetchCount": 25,
        "QueueTimeout": "00:00:01",
        "RequestedHeartbeat": "00:00:30",
        "ConnectionCloseTimeout": "00:00:01",
        "OperationRetryCount": 3,
        "Priority": 0,
        "Persistent": true,
        "Durable": true
      }
    }
  }
}

Options

OptionDefaultDescription
ConnectionFactorynullThe RabbitMQ.Client.ConnectionFactory instance. If null and instance will be created and populated using the relevant values in the options; else it should be pre-configured fully.
HostThe RabbitMQ host to connect to.
VirtualHost"/"The virtual host to connect to.
Port-1Specifies the port to connect to. A value of -1 represents AmqpTcpEndpoint.UseDefaultPort.
UsernameThe username to send as a credential.
PasswordThe password to send as a credential.
PrefetchCount25Specifies the number of messages to prefetch from the queue.
QueueTimeout00:00:01How long to wait when retrieving a message from the queue before timing out and returing null.
RequestedHeartbeat00:00:30Heartbeat timeout to use when negotiating with the server.
ConnectionCloseTimeout00:00:01The duration to wait wait for connections to be closed.
OperationRetryCount3How many times to retry relevant queue operations in the event that they fail. Once the retries have run out the original exception is thrown.
Priority0Determines the number of priorities (x-max-priority) supported by the queue.
PersistenttrueDetermines whether messages will be persisted. Please be sure of the possible consequences before setting to 'false'.
DurabletrueDetermines whether the queue is durable. Please be sure of the possible consequences before setting to 'false'.