This class represents a RouterEnvelope that can be wrapped around a message in order to make it hashable for use with ConsistentHashingGroup or ConsistentHashingPool routers.
Наследование: RouterEnvelope, IConsistentHashable
Пример #1
0
        public MainModule()
        {
            Get["/"] = x =>
            {
                var repo = new PersonRepository();
                var persons = repo.GetAll();
                return Response.AsJson(persons);
            };

            //Post["/"] = x =>
            //{
            //    var person = this.Bind<Person>();
            //    var repo = new PersonRepository();
            //    if (!repo.Exists(person.Name))
            //    {
            //        Console.WriteLine("Person with name {0} was added", person.Name);
            //        repo.Add(person);
            //    }
            //    else
            //    {
            //        Console.WriteLine("Person with name {0} already exists", person.Name);
            //    }

            //    return (Response)"OK";
            //};

            Post["/", true] = async (x, ct) =>
            {
                var person = this.Bind<Person>();
                var envelope = new ConsistentHashableEnvelope(person,person.Name);
                var result = await AkkaUtil.PersonPostActor.Ask<string>(envelope);
                return (Response) result;

            };
        }
Пример #2
0
        private static void WithHashPool()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<TypedWorker>();

            var container = builder.Build();


            using (var system = ActorSystem.Create("MySystem"))
            {
                var propsResolver =
                    new AutoFacDependencyResolver(container, system);

                var router = system.ActorOf(system.DI().Props<TypedWorker>().WithRouter(FromConfig.Instance), "router1");

                Task.Delay(500).Wait();
                Console.WriteLine("Sending Messages");

                for (var i = 0; i < 5; i++)
                {
                    for (var j = 0; j < 7; j++)
                    {

                        var msg = new TypedActorMessage { Id = j, Name = Guid.NewGuid().ToString() };
                        var ms = new AnotherMessage { Id = j, Name = msg.Name };

                        var envelope = new ConsistentHashableEnvelope(ms, msg.Id);

                        router.Tell(msg);
                        router.Tell(envelope);

                    }
                }
                Console.WriteLine("Hit Enter to close");
                Console.ReadLine();
            }

            
        }
Пример #3
0
        private static void WithHashPool()
        {
            IContainer container = new Container(cfg =>
            {
                cfg.For<TypedWorker>().Use<TypedWorker>().Named("TypedWorker").LifecycleIs<TransientLifecycle>();
            });
            
            using (var system = ActorSystem.Create("MySystem"))
            {
                var propsResolver =
                    new StructureMapDependencyResolver(container, system);

                var router = system.ActorOf(system.DI().Props<TypedWorker>().WithRouter(FromConfig.Instance), "router1");

                Task.Delay(500).Wait();
                Console.WriteLine("Sending Messages");
                for (var i = 0; i < 5; i++)
                {
                    for (var j = 0; j < 7; j++)
                    {

                        var msg = new TypedActorMessage { Id = j, Name = Guid.NewGuid().ToString() };
                        var ms = new AnotherMessage { Id = j, Name = msg.Name };

                        var envelope = new ConsistentHashableEnvelope(ms, msg.Id);

                        router.Tell(msg);
                        router.Tell(envelope);

                    }
                }
                Console.WriteLine("Hit Enter to exit");
                Console.ReadLine();
            }


        }