Skip to content

Instantly share code, notes, and snippets.

@anavarro9731
Created September 16, 2011 07:07
Show Gist options
  • Save anavarro9731/1221414 to your computer and use it in GitHub Desktop.
Save anavarro9731/1221414 to your computer and use it in GitHub Desktop.
eventstore example demonstrating transaction aborted error with ravenpersistence
using System.Transactions;
namespace EventStore.Example
{
using System;
internal static class MainProgram
{
private static readonly Guid StreamId = Guid.NewGuid(); // aggregate identifier
private static IStoreEvents store;
private static void Main()
{
store = WireupEventStore();
AttemptToCreateTwoStreamsWithTheSameId();
Console.WriteLine(Resources.PressAnyKey);
Console.ReadLine();
}
private static IStoreEvents WireupEventStore()
{
return Wireup.Init()
.LogToConsoleWindow()
.UsingRavenPersistence(@"RavenDB")
.EnlistInAmbientTransaction()
.InitializeStorageEngine()
.Build();
}
private static void AttemptToCreateTwoStreamsWithTheSameId()
{
var @event = new SomeDomainEvent { Value = "Initial event1." };
//simulate message one
using (var t = new TransactionScope())
{
var stream = store.OpenStream(StreamId, 0, int.MaxValue);
stream.Add(new EventMessage { Body = @event });
stream.CommitChanges(Guid.NewGuid());
t.Complete();
}
//simulate message two
using (var t = new TransactionScope())
{
var stream2 = store.OpenStream(StreamId, 0, int.MaxValue);
stream2.Add(new EventMessage { Body = @event });
stream2.CommitChanges(Guid.NewGuid());
t.Complete();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment