Idle Subscription Cleanup for NATS, RabbitMQ, SQL Server and Postgres

• Damian Maclennan
releases transports nats rabbitmq sql-server postgres

The NATS, RabbitMQ, SQL Server and Postgres transports are all now at 1.1.0. The headline change is the same one Redis got in 4.4.0: orphaned event subscriptions are cleaned up automatically.

What changed

Every multicast event subscriber gets its own per-instance subscription, named from the instance name you pass to WithNames. On Kubernetes, ECS and similar platforms that name changes on every deploy, so each one leaves a subscription behind that nothing will ever consume, and messages keep being fanned out to it.

1.1.0 fixes this on each transport using whatever the backend does best:

The AMQP transport is unchanged. Durable subscriptions there are owned by the broker, so the AMQP docs now explain how to configure cleanup on the broker side instead.

Configuring the idle window

The window is the same on all four transports. It defaults to 4 days, with a 5 minute minimum:

var bus = new BusBuilder()
    .Configure()
    .WithNames("OrderService", Environment.MachineName)
    .WithTransport(new RabbitMqTransportConfiguration().WithHost("localhost"))
    .WithAutoDeleteOnIdle(TimeSpan.FromDays(1)) // Optional, defaults to 4 days, minimum 5 minutes
    .WithTypesFrom(typeProvider)
    .WithAutofacDefaults(container)
    .Build();

A running instance never expires, so the window only matters once an instance stops. If an instance stays down longer than the window, events published in the meantime are not delivered when it returns. Raise WithAutoDeleteOnIdle if your instances routinely go quiet for long periods.

Upgrading

dotnet add package Nimbus.Transports.Nats --version 1.1.0
dotnet add package Nimbus.Transports.RabbitMQ --version 1.1.0
dotnet add package Nimbus.Transports.SqlServer --version 1.1.0
dotnet add package Nimbus.Transports.Postgres --version 1.1.0

No breaking changes, and the idle window is optional. Two things to know:

Full details are in the NATS, RabbitMQ, SQL Server and Postgres transport docs.

← Back to Blog