Getting Started

RavenDB Gateway Storage

NuGet Package: NServiceBus.Gateway.RavenDB (2.x)
Target Version: NServiceBus 7.x

Provides deduplication storage for the gateway component in RavenDB.


var gatewayConfiguration = new RavenGatewayDeduplicationConfiguration((builder, _) =>
    var documentStore = new DocumentStore
        Urls = new[] { "database-server-url" },
        Database = "default-database-name"


    return documentStore;
    // When running in a cluster, enable cluster wide transaction support
    EnableClusterWideTransactions = true,

var gatewaySettings = endpointConfiguration.Gateway(gatewayConfiguration);

Cleaning up old records

After a certain amount of time, duplicates are no longer likely and deduplication data should be cleaned up. The RavenDB gateway storage component provides a built-in mechanism based on the RavenDB Expiration feature which is activated by default on the database server.

Deduplication data is kept for 7 days by default, and the cleanup job is executed every 10 minutes. To customize the expiration policy use DeduplicationDataTimeToLive and FrequencyToRunDeduplicationDataCleanup, as shown below:

gatewayConfiguration.DeduplicationDataTimeToLive = TimeSpan.FromDays(15);
gatewayConfiguration.FrequencyToRunDeduplicationDataCleanup = 86400;

In this example, deduplication data are preserved for 15 days and cleanup is run every 24 hours.

While it is possible to use the same deduplication database for all endpoints within a single logical site, the gateway assumes that different logical sites (which are generally physically separated as well) will use separate storage infrastructure. Sending a message to multiple sites will result in messages with the same message ID delivered to each site, if those sites share a single deduplication table, the deduplication will not work correctly. In that case, separate the storage by using different database names.