Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
public class RavenDbMessageModule : IMessageModule
{
private readonly IDocumentStore documentStore;
[ThreadStatic]
private static IDocumentSession currentSession;
public static IDocumentSession CurrentSession
{
get { return currentSession; }
}
public RavenDbMessageModule(IDocumentStore documentStore)
{
this.documentStore = documentStore;
}
public void Init(ITransport transport, IServiceBus serviceBus)
{
transport.MessageArrived += TransportOnMessageArrived;
transport.MessageProcessingCompleted += TransportOnMessageProcessingCompleted;
}
public void Stop(ITransport transport, IServiceBus serviceBus)
{
transport.MessageArrived -= TransportOnMessageArrived;
transport.MessageProcessingCompleted -= TransportOnMessageProcessingCompleted;
}
private static void TransportOnMessageProcessingCompleted(CurrentMessageInformation currentMessageInformation, Exception exception)
{
if (currentSession != null)
{
if (exception == null)
currentSession.SaveChanges();
currentSession.Dispose();
}
currentSession = null;
}
private bool TransportOnMessageArrived(CurrentMessageInformation currentMessageInformation)
{
if (currentSession == null)
currentSession = documentStore.OpenSession();
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.