# RabbitMQ Sink

<ConnectorLogo name="rabbitmq" alt="RabbitMQ" />

The RabbitMQ sink publishes records from a KurrentDB stream to a RabbitMQ exchange using a routing key. The exchange
routes each message to the destination queues bound to that key, so the sink does not manage exchanges or queues
itself. It handles errors and recovers from them to keep message delivery consistent in production.

## Prerequisites

Before using the RabbitMQ sink connector, ensure you have:

- A data protection token configured in your KurrentDB instance (required to encrypt sensitive fields like passwords)
- A RabbitMQ server instance with accessible host and port
- Appropriate authentication credentials (username and password)

:::tip
See the [Data Protection](/kurrent-surge/client/connectors/data-protection/) documentation for instructions on configuring the encryption token.
:::

## Quickstart

Create the RabbitMQ sink with `client.Connectors`. Replace `example-rabbitmq` with your own
connector id:

```csharp
Dictionary<string, string> settings = new() {
    ["instanceTypeName"]               = "rabbit-mq-sink",
    ["exchange:name"]                  = "example-exchange",
    ["exchange:type"]                  = "direct",
    ["routingKey"]                     = "my-routing-key",
    ["subscription:filter:scope"]      = "stream",
    ["subscription:filter:filterType"] = "streamId",
    ["subscription:filter:expression"] = "example-stream"
};

await client.Connectors.Create("example-rabbitmq", settings);
await client.Connectors.Start("example-rabbitmq");
```

Once started, the connector sends each record appended to `example-stream` to the exchange,
which routes it to the bound queues. [Managing Connectors](/kurrent-surge/client/connectors/manage/)
covers the rest of the lifecycle.

## Settings

Adjust these settings to control how the RabbitMQ sink connector behaves and how it interacts with KurrentDB.

:::tip
The RabbitMQ sink inherits a set of common settings that are used to configure the connector. The settings can be found in
the [Sink Options](/kurrent-surge/client/connectors/sinks/#settings) page.
:::

The RabbitMQ sink can be configured with the following options:

| Option                            | Description                                                                                                                                                                                                                                                                    |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `exchange:name`                   | _required_<br/><br/>**Description:**<br/>Exchange's name.                                                                                                                                                                                                                         |
| `exchange:type`                   | **Description:**<br/>Exchange's type.<br/><br/>**Default**: `"fanout"`                                                                                                                                                                                                            |
| `routingKey`                      | **Description:**<br/>Used by the exchange to determine how to route a message to the appropriate queue(s). The exchange evaluates the routing key against the binding rules of its associated queues, which shapes the message's delivery path.<br/><br/>**Default**: `""` |
| `host`                            | **Description:**<br/>Hostname of the server.<br/><br/>**Default**: `"localhost"`                                                                                                                                                                                                  |
| `port`                            | **Description:**<br/>Port number of the server.<br/><br/>**Default**: `"5672"`                                                                                                                                                                                                    |
| `connectionName`                  | **Description:**<br/>Connection name used for logging and diagnostics. The default value is the connector ID.<br/><br/>**Default**: The connector id                                                                             |
| `virtualHost`                     | **Description:**<br/>Represents the VirtualHost (vhost) used in RabbitMQ. <br/><br/>**Default**: `/`                                                                                                                                                                              |
| `waitForBrokerAck`                | **Description:**<br/>Whether the channel waits for broker acknowledgment before considering the send operation complete.<br/><br/>**Default**: `"false"`                                                                                                                          |
| `authentication:username`         | **Description:**<br/>Username for authentication.<br/><br/>**Default**: `"guest"`                                                                                                                                                                                                 |
| `authentication:password`         | **Description:**<br/>Password for authentication.<br/><br/>**Default**: `"guest"`                                                                                                                                                                                                 |
| `autoDelete`                      | **Description:**<br/>Whether the exchange is automatically deleted when no longer in use.<br/><br/>**Default**: `"false"`                                                                                                                                                         |
| `durable`                         | **Description:**<br/>Whether the exchange is durable.<br/><br/>**Default**: `"true"`                                                                                                                                                                                              |

### Resilience

The RabbitMQ sink connector relies on its own RabbitMQ retry mechanism and doesn't include the configuration from [Resilience configuration](/kurrent-surge/client/connectors/sinks/#resilience-settings).

| Option                            | Description                                                                                                                                                                                                                                                                    |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `resilience:connectionTimeoutMs`  | **Description:**<br/>Connection TCP establishment timeout in milliseconds. 0 for infinite.<br/><br/>**Default**: `"60000"`                                                                                                                                                        |
| `resilience:handshakeTimeoutMs`   | **Description:**<br/>The protocol handshake timeout in milliseconds.<br/><br/>**Default**: `"10000"`                                                                                                                                                                              |
| `resilience:requestedHeartbeatMs` | **Description:**<br/>The requested heartbeat timeout in milliseconds. 0 means "heartbeats are disabled". Should be no lower than 1 second.<br/><br/>**Default**: `"60000"`                                                                                                        |

## Delivery guarantees

By default, the connector does not wait for broker acknowledgment. Enable it, and the broker confirms each message sent
to RabbitMQ before the connector treats the publish operation as complete:

```json
{
  "waitForBrokerAck": "true"
}
```

Disabling broker acknowledgment can significantly increase throughput, because the producer keeps sending messages
without waiting for the broker's confirmation. Use it when throughput matters more than delivery guarantees, and accept
a slightly higher risk of message loss or duplication.

## Headers

The RabbitMQ sink connector automatically includes these [default headers](/kurrent-surge/client/connectors/sinks/#headers) in each message sent to the exchange. 

## Tutorial
[Learn how to set up and use a RabbitMQ Sink connector in KurrentDB through a tutorial.](https://docs.kurrent.io/server/v26.1/tutorials/RabbitMQ_Sink)