コード例 #1
0
        public static IActorRef CategoryCommanderAggregate(this IActorRefFactory system, Guid id,
                                                           int snapshotThreshold = 2)
        {
            var nameOfCommanderActor  = SystemData.CategoryCommanderActor.Name;
            var nameofProjectionActor = SystemData.CategoryProjectionsActor.Name;
            // var nameOfProcessManagerActor = "category-process-manager";

            // build up the category actor
            var projectionsProps = new ConsistentHashingPool(10)
                                   .Props(Props.Create <ReadModelProjections>());
            var projections = system.ActorOf(projectionsProps, $"{nameofProjectionActor}-{nameOfCommanderActor}");

            /*var processManagerProps = new ConsistentHashingPool(1)
             *  .Props(Props.Create(() => new CategoryProcessManager(id)));*/
            // var processManager = system.ActorOf(Props.Create(() => new CategoryProcessManager(id)));
            // var categoryStatusSaga = system.ActorSelection($"/user/{SystemData.CategoryStatusSagaActor.Name}-group");

            var categoryStatusSagaActor = system.ActorOf(
                Props.Empty.WithRouter(FromConfig.Instance), "category-status-broadcaster-group");

            var creationParams = new AggregateRootCreationParameters(id, projections,
                                                                     new HashSet <IActorRef>(new List <IActorRef> {
                categoryStatusSagaActor
            }), snapshotThreshold);

            return(system.ActorOf(Props.Create <Category>(creationParams), nameOfCommanderActor));
        }
コード例 #2
0
        public static IActorRef CategoryCommanderAggregate(this IActorRefFactory system, Guid id,
                                                           int snapshotThreshold = 10)
        {
            var nameOfCommanderActor  = SystemData.CategoryCommanderActor.Name;
            var nameofProjectionActor = SystemData.CategoryProjectionsActor.Name;
            // build up the category actor
            var projectionsProps = new ConsistentHashingPool(5).Props(Props.Create <ReadModelProjections>());
            var projections      = system.ActorOf(projectionsProps, nameofProjectionActor + $"-{nameOfCommanderActor}");
            var creationParams   = new AggregateRootCreationParameters(id, projections, snapshotThreshold);

            return(system.ActorOf(Props.Create <Category>(creationParams), nameOfCommanderActor));
        }
コード例 #3
0
        public Category(AggregateRootCreationParameters parameters)
            : base(parameters)
        {
            _state = new CategoryState {
                EventSink = this
            };

            // register sagas
            ActorSelections = new HashSet <ActorSelection>
            {
                Context.ActorSelection("/user/category-status-broadcaster-group")
            };
        }
コード例 #4
0
 public Category(AggregateRootCreationParameters parameters)
     : base(parameters)
 {
     _state = new CategoryState(this);
 }
コード例 #5
0
ファイル: Tenant.cs プロジェクト: chandan-97-source/hotdog
 public Tenant(AggregateRootCreationParameters parameters)
     : base(parameters)
 {
 }
        private void Ready()
        {
            _log.Debug("AggregateRootCoordinatorActor entering Ready state");
            Receive <IAccountMessage>(msg =>
            {
                //forward on
                if (!_accountWorkerRefs.ContainsKey(msg.AccountId))
                {
                    var accountProjection = Context.ActorOf(Props.Create <AccountProjection>(msg.AccountId));
                    var parms             = new AggregateRootCreationParameters(
                        msg.AccountId,
                        new List <IActorRef>()
                    {
                        _accountIndexProjection, accountProjection
                    },
                        snapshotThreshold: 5,
                        receiveTimeout: TimeSpan.FromMinutes(2)
                        );
                    //register our projection
                    _registry.Tell(new RegisterProjection(msg.AccountId, accountProjection));
                    _accountWorkerRefs.Add(msg.AccountId,
                                           Context.ActorOf(Props.Create <AccountActor>(parms), "aggregates(account)" + msg.AccountId.ToString()));

                    _log.Debug("Account:{0}, Added to Agg Root Coordinator Cache", msg.AccountId);
                }
                _accountWorkerRefs[msg.AccountId].Forward(msg);
            });

            Receive <PassivateMessage>(msg =>
            {
                _log.Debug("Account:{0}, timed out, due to inactivity", msg.Id);
                var actorToUnload = Context.Sender;
                actorToUnload.GracefulStop(TimeSpan.FromSeconds(10)).ContinueWith((success) =>
                {
                    if (success.Result)
                    {
                        _accountWorkerRefs.Remove(msg.Id);
                        _log.Debug("Account:{0}, removed", msg.Id);
                    }
                    else
                    {
                        _log.Warning("Account:{0}, failed to removed", msg.Id);
                    }
                });

                // the time between the above and below lines, we need to intercept messages to the child that is being
                // removed from memory - how to do this?

                //task.Wait(); // dont block thread, use pipeto instead?
            });

            Receive <GetProjection>(msg =>
            {
                _log.Debug("GetProjection requested ", msg.Key);
                _registry.Forward(msg);
            });

            Receive <GetIndexProjection>(msg =>
            {
                _log.Debug("GetIndexProjection requested ", msg.Key);
                _registry.Forward(msg);
            });
        }