private async Task ResetAsync(IEventConsumer eventConsumer, string consumerName) { var actionId = Guid.NewGuid().ToString(); try { log.LogInformation(w => w .WriteProperty("action", "EventConsumerReset") .WriteProperty("actionId", actionId) .WriteProperty("state", "Started") .WriteProperty("eventConsumer", eventConsumer.GetType().Name)); await eventConsumer.ClearAsync(); await eventConsumerInfoRepository.SetLastHandledEventNumberAsync(consumerName, -1); log.LogInformation(w => w .WriteProperty("action", "EventConsumerReset") .WriteProperty("actionId", actionId) .WriteProperty("state", "Completed") .WriteProperty("eventConsumer", eventConsumer.GetType().Name)); } catch (Exception ex) { log.LogFatal(ex, w => w .WriteProperty("action", "EventConsumerReset") .WriteProperty("actionId", actionId) .WriteProperty("state", "Completed") .WriteProperty("eventConsumer", eventConsumer.GetType().Name)); throw; } }
public static void AddEventConsumer(this IServiceCollection services, IEventConsumer consumer) { if (!IsValidConsumer(consumer.GetType())) { throw new ArgumentException( $"{consumer.GetType()} must also implement {typeof(IEventConsumer<>)}.", nameof(consumer)); } services.AddSingleton(consumer); }
public EventConsumerGrainTests() { state.Position = initialPosition; consumerName = eventConsumer.GetType().Name; A.CallTo(() => store.WithSnapshots(A <Type> .Ignored, consumerName, A <Func <EventConsumerState, Task> > .Ignored)) .Invokes(new Action <Type, string, Func <EventConsumerState, Task> >((t, key, a) => { apply = a; })) .Returns(persistence); A.CallTo(() => eventStore.CreateSubscription(A <IEventSubscriber> .Ignored, A <string> .Ignored, A <string> .Ignored)) .Returns(eventSubscription); A.CallTo(() => eventConsumer.Name) .Returns(consumerName); A.CallTo(() => persistence.ReadAsync(EtagVersion.Any)) .Invokes(new Action <long>(s => apply(state))); A.CallTo(() => persistence.WriteSnapshotAsync(A <EventConsumerState> .Ignored)) .Invokes(new Action <EventConsumerState>(s => state = s)); A.CallTo(() => formatter.Parse(eventData, null)) .Returns(envelope); sut = new MyEventConsumerGrain( x => eventConsumer, store, eventStore, formatter, log); }
public EventConsumerGrainTests() { grainState.Value.Position = initialPosition; consumerName = eventConsumer.GetType().Name; A.CallTo(() => eventStore.CreateSubscription(A <IEventSubscriber> .Ignored, A <string> .Ignored, A <string> .Ignored)) .Returns(eventSubscription); A.CallTo(() => eventConsumer.Name) .Returns(consumerName); A.CallTo(() => eventConsumer.Handles(A <StoredEvent> .Ignored)) .Returns(true); A.CallTo(() => formatter.Parse(eventData, null)) .Returns(envelope); sut = new MyEventConsumerGrain( x => eventConsumer, grainState, eventStore, formatter, log); }
public EventConsumerGrainTests() { state.Position = initialPosition; consumerName = eventConsumer.GetType().Name; A.CallTo(() => eventStore.CreateSubscription(A <IEventSubscriber> .Ignored, A <string> .Ignored, A <string> .Ignored)) .Returns(eventSubscription); A.CallTo(() => eventConsumer.Name). Returns(consumerName); A.CallTo(() => stateHolder.State) .ReturnsLazily(() => state); A.CallToSet(() => stateHolder.State) .Invokes(new Action <EventConsumerState>(s => state = s)); A.CallTo(() => formatter.Parse(eventData, true)).Returns(envelope); sut = new MyEventConsumerGrain(formatter, eventStore, log); sutSubscriber = sut; sut.ActivateAsync(stateHolder).Wait(); }
public CompoundEventConsumer(IEventConsumer first, params IEventConsumer[] inners) { Guard.NotNull(first, nameof(first)); Guard.NotNull(inners, nameof(inners)); this.inners = new[] { first }.Union(inners).ToArray(); Name = first.GetType().Name; }
private async Task DispatchConsumer(Envelope <IEvent> @event, IEventConsumer eventConsumer) { var eventId = @event.Headers.EventId().ToString(); var eventType = @event.Payload.GetType().Name; try { log.LogInformation(w => w .WriteProperty("action", "HandleEvent") .WriteProperty("actionId", eventId) .WriteProperty("state", "Started") .WriteProperty("eventId", eventId) .WriteProperty("eventType", eventType) .WriteProperty("eventConsumer", eventConsumer.GetType().Name)); await eventConsumer.On(@event); log.LogInformation(w => w .WriteProperty("action", "HandleEvent") .WriteProperty("actionId", eventId) .WriteProperty("state", "Completed") .WriteProperty("eventId", eventId) .WriteProperty("eventType", eventType) .WriteProperty("eventConsumer", eventConsumer.GetType().Name)); } catch (Exception ex) { log.LogError(ex, w => w .WriteProperty("action", "HandleEvent") .WriteProperty("actionId", eventId) .WriteProperty("state", "Started") .WriteProperty("eventId", eventId) .WriteProperty("eventType", eventType) .WriteProperty("eventConsumer", eventConsumer.GetType().Name)); throw; } }
public EventConsumerGrainTests() { grainState.Value = new EventConsumerState { Position = initialPosition }; consumerName = eventConsumer.GetType().Name; A.CallTo(() => eventStore.CreateSubscription(A <IEventSubscriber> ._, A <string> ._, A <string> ._)) .Returns(eventSubscription); A.CallTo(() => eventConsumer.Name) .Returns(consumerName); A.CallTo(() => eventConsumer.Handles(A <StoredEvent> ._)) .Returns(true); A.CallTo(() => eventConsumer.On(A <IEnumerable <Envelope <IEvent> > > ._)) .Invokes((IEnumerable <Envelope <IEvent> > events) => { foreach (var @event in events) { eventConsumer.On(@event).Wait(); } }); A.CallTo(() => eventSubscription.Sender) .Returns(eventSubscription); storedEvent = new StoredEvent("Stream", Guid.NewGuid().ToString(), 123, eventData); A.CallTo(() => formatter.ParseIfKnown(storedEvent)) .Returns(envelope); var log = A.Fake <ILogger <EventConsumerGrain> >(); sut = new MyEventConsumerGrain( x => eventConsumer, grainState, eventStore, formatter, log); }
public EventConsumerActorTests() { consumerInfo.Position = Guid.NewGuid().ToString(); consumerName = eventConsumer.GetType().Name; A.CallTo(() => eventStore.CreateSubscription(A <IEventSubscriber> .Ignored, A <string> .Ignored, A <string> .Ignored)).Returns(eventSubscription); A.CallTo(() => eventConsumer.Name).Returns(consumerName); A.CallTo(() => eventConsumerInfoRepository.FindAsync(consumerName)).Returns(consumerInfo); A.CallTo(() => formatter.Parse(eventData, true)).Returns(envelope); sut = new EventConsumerActor(formatter, eventStore, eventConsumerInfoRepository, log) { ReconnectWaitMs = 0 }; sutActor = sut; sutSubscriber = sut; }
public EventConsumerGrainTests() { grainState.Value = new EventConsumerState { Position = initialPosition }; consumerName = eventConsumer.GetType().Name; A.CallTo(() => eventStore.CreateSubscription(A <IEventSubscriber> ._, A <string> ._, A <string> ._)) .Returns(eventSubscription); A.CallTo(() => eventConsumer.Name) .Returns(consumerName); A.CallTo(() => eventConsumer.Handles(A <StoredEvent> ._)) .Returns(true); A.CallTo(() => eventConsumer.On(A <IEnumerable <Envelope <IEvent> > > ._)) .Invokes((IEnumerable <Envelope <IEvent> > events) => { foreach (var @event in events) { eventConsumer.On(@event).Wait(); } }); A.CallTo(() => eventSubscription.Sender) .Returns(eventSubscription); A.CallTo(() => formatter.ParseIfKnown(A <StoredEvent> .That.Matches(x => x.Data == eventData))) .Returns(envelope); sut = new MyEventConsumerGrain( x => eventConsumer, grainState, eventStore, formatter, log); }
public EventReceiverTests() { var events = new[] { new StoredEvent("3", 3, eventData1), new StoredEvent("4", 4, eventData2), new StoredEvent("5", 5, eventData3) }; consumerName = eventConsumer.GetType().Name; var eventStore = new MyEventStore(events); A.CallTo(() => eventConsumer.Name).Returns(consumerName); A.CallTo(() => eventConsumerInfoRepository.FindAsync(consumerName)).Returns(Task.FromResult <IEventConsumerInfo>(consumerInfo)); A.CallTo(() => formatter.Parse(eventData1)).Returns(envelope1); A.CallTo(() => formatter.Parse(eventData2)).Returns(envelope2); A.CallTo(() => formatter.Parse(eventData3)).Returns(envelope3); sut = new EventReceiver(formatter, eventStore, eventConsumerInfoRepository, log); }