Skip to content

RabbitMQ Sink

License Required

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.

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)

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

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 covers the rest of the lifecycle.

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

The RabbitMQ sink can be configured with the following options:

Option Description
exchange:name required

Description:
Exchange’s name.
exchange:type Description:
Exchange’s type.

Default: "fanout"
routingKey Description:
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.

Default: ""
host Description:
Hostname of the server.

Default: "localhost"
port Description:
Port number of the server.

Default: "5672"
connectionName Description:
Connection name used for logging and diagnostics. The default value is the connector ID.

Default: The connector id
virtualHost Description:
Represents the VirtualHost (vhost) used in RabbitMQ.

Default: /
waitForBrokerAck Description:
Whether the channel waits for broker acknowledgment before considering the send operation complete.

Default: "false"
authentication:username Description:
Username for authentication.

Default: "guest"
authentication:password Description:
Password for authentication.

Default: "guest"
autoDelete Description:
Whether the exchange is automatically deleted when no longer in use.

Default: "false"
durable Description:
Whether the exchange is durable.

Default: "true"

The RabbitMQ sink connector relies on its own RabbitMQ retry mechanism and doesn’t include the configuration from Resilience configuration.

Option Description
resilience:connectionTimeoutMs Description:
Connection TCP establishment timeout in milliseconds. 0 for infinite.

Default: "60000"
resilience:handshakeTimeoutMs Description:
The protocol handshake timeout in milliseconds.

Default: "10000"
resilience:requestedHeartbeatMs Description:
The requested heartbeat timeout in milliseconds. 0 means “heartbeats are disabled”. Should be no lower than 1 second.

Default: "60000"

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:

{
"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.

The RabbitMQ sink connector automatically includes these default headers in each message sent to the exchange.

Learn how to set up and use a RabbitMQ Sink connector in KurrentDB through a tutorial.