Hi all,
Did anyone played with the methods above from the EventStoreConnection or can someone please describe what would be scenario for using them.
My aim would be to create read model soon as event is stored, within same process and try to store it somewhere (document database or relation one).
If storing of the read model fails I would like to know from where to replay events in order to rebuild it.(Is this to complicated, any other simpler way without having to query eventstore projections?)
One question what puzzles me: Does SubscribeAsync lives only within open connection r it is stored in the store forever until we Unsubscribe from it, what means we have to maintain subscriptions.
From the client code I can see that the subscribe request is sent to the store, but don’t know where to see how many subscriptions are registered in the store if they are persistent within store.
Below code does not work and if someone know why or what I’m doing wrong please let me know.
public void StoreAggregateChanges(T aggregateInstance) where T : IAggregate
{
string streamId = GetStreamId(aggregateInstance.GetType(), aggregateInstance.Id);
var tempSubscribe = new StreamSubsciption(streamId);
using (EventStoreConnection storeConnection = EventStoreConnection.Create())
{
storeConnection.Connect(_endpoint);
storeConnection.SubscribeAsync(tempSubscribe.StreamName, tempSubscribe.EventRecorded,
tempSubscribe.SubscriptionFailed);
storeConnection.AppendToStream(streamId, ExpectedVersion.Any,
aggregateInstance.GetUnocommittedEventsForEventStore());
aggregateInstance.ClearUncommittedEvents();
** storeConnection.UnsubscribeAsync(streamId); with this line SubscriptionFailed method is called, do I need this line? when I comment out this line EventRecorded work fine but will I end up with long living subscriptions what I don’t need**
}
}
internal class StreamSubsciption
{
public readonly string StreamName;
public StreamSubsciption(string streamName)
{
Console.WriteLine(“Stream name:{0}”,streamName);
StreamName = streamName;
}
public void EventRecorded(RecordedEvent recordedEvent, Position position)
{
Console.Write(“ThredId:{0}”,System.Threading.Thread.CurrentThread.ManagedThreadId);
Console.WriteLine(“recorded event id:{0},Position Commit:{1},Prepare:{2}”,recordedEvent.EventId,position.CommitPosition,position.PreparePosition);
}
public void SubscriptionFailed()
{
Console.WriteLine(“Failed”);
//nooonoo
}
}
Cheers Tom