Created
September 16, 2011 07:07
-
-
Save anavarro9731/1221414 to your computer and use it in GitHub Desktop.
eventstore example demonstrating transaction aborted error with ravenpersistence
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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