public virtual async Task <int> ReactAsync(SubscribedAggregateChanged msg, IUnitOfWork uow)
        {
            //load any events that we haven't dispatched yet
            var stream = storeEvents.LoadUndispatchedEvents(uow, msg);

            foreach (EventMessage eventMessage in stream.CommittedEvents)
            {
                await dispatcher.DispatchPayloadAsync(this, eventMessage.Body);
            }
            return(stream.StreamRevision);
        }
Example #2
0
        /// <summary>
        /// Loads the events from the eventstream which have not yet been dispatched to the Reactor
        /// </summary>
        /// <param name="storeEvents"></param>
        /// <param name="uow"></param>
        /// <param name="msg"></param>
        /// <returns>IEventStream the (partial) stream of events which have not yet been dispatched to the Reactor</returns>
        public static IEventStream LoadUndispatchedEvents(this IStoreEvents storeEvents, IUnitOfWork uow, SubscribedAggregateChanged msg)
        {
            int fromStreamRevision =
                uow.PersistedPubSub
                .Map(previous => previous.AggregateSubscriptions.First(x => x.AggregateId == msg.AggregateId).StreamRevision + 1)
                .GetOrElse(1);

            return(LoadUndispatchedEvents(storeEvents, msg.AggregateId, fromStreamRevision));
        }
Example #3
0
        public void Tell(SubscribedAggregateChanged msg)
        {
            var mediator = DistributedPubSub.Get(system).Mediator;

            mediator.Tell(new Publish(ReactorBucketSupervisor.GetInternalPublicationTopic(msg.ReactorBucket), msg));
        }
Example #4
0
 /// <summary>
 /// Route the message to a child ReactorActor who will actually update the reactor
 /// </summary>
 /// <param name="msg"></param>
 /// <returns></returns>
 private Task OnSubscribedAggregateChangedAsync(SubscribedAggregateChanged msg)
 {
     Context.ActorSelection(ReactorActorsRelativeAddress).Tell(msg);
     return(Task.CompletedTask);
 }