Redis Persistence for NServiceBus 4.4.x.
Version 1.x supports only TimeoutManager (IPersistTimeouts).
Redis connection is based on ServiceStack.Redis
library latest .NET 4.5 version
.
- Get the source and build locally
or - Install the
NServiceBus.Redis
NuGet package using the Visual Studio NuGet Package Manager or Package Manager
Install-Package NServiceBus.Redis -Version 1.1.0
After adding a reference to it from your project, specify RedisPersistence
to be used for persistence.
using NServiceBus;
using NServiceBus.Redis;
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
public void Init()
{
var conf = Configure.With();
conf.UseRedisTimeoutPersister(endpointName);
//or
conf.UseRedisTimeoutPersister(endpointName, defaultPollingTimeout = 5); //MINUTES, default 10
}
}
This base configuration connects using redis settings strings in the app.config.
<appSettings>
<add key="NServiceBus/Redis/RedisSentinelHosts" value=""/>
<add key="NServiceBus/Redis/RedisClusterName" value=""/>
<add key="NServiceBus/Redis/RedisConnectionString" value="redis://localhost?db=0;"/>
</appSettings>
It is possible to pass an already configured instance of IRedisClientsManager.
using NServiceBus;
using NServiceBus.Redis;
public class EndpointConfig : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
public void Init()
{
var conf = Configure.With();
var yourRedisClientsManagerInstance = new RedisManagerPool(redisConnectionString);
conf.UseRedisTimeoutPersister(endpointName, yourRedisClientsManagerInstance);
//or
conf.UseRedisTimeoutPersister(endpointName, yourRedisClientsManagerInstance, defaultPollingTimeout = 5); //MINUTES, default 10
}
}