public IActorRef StartProxy(ActorSystem system)
 {
     return(ClusterSharding.Get(system).StartProxy(
                Name,
                "worker",
                new T()
                ));
 }
コード例 #2
0
 public MetricsActorSpec() :
     base(CLUSTERSHARDCONFIG)
 {
     cluster        = Cluster.Get(Sys);
     clusterMetrics = ClusterMetrics.Get(Sys);
     ClusterSharding.Get(Sys).Start(typeName: ShardRegions.OBJECTREGION, entityProps: Props.Create(() => new ObjectActor(null)), settings: ClusterShardingSettings.Create(Sys), messageExtractor: new ObjectRegionMessageExtractor(10));
     ClusterSharding.Get(Sys).Start(typeName: ShardRegions.AREAREGION, entityProps: Props.Create(() => new ObjectActor(null)), settings: ClusterShardingSettings.Create(Sys), messageExtractor: new AreaRegionMessageExtractor(10));
 }
コード例 #3
0
        public ProxyShardingSpec() : base(GetConfig())
        {
            var role = "Shard";

            clusterSharding  = ClusterSharding.Get(Sys);
            shardingSettings = ClusterShardingSettings.Create(Sys);
            clusterSharding.StartProxy("myType", role, IdExtractor, ShardResolver);
        }
コード例 #4
0
        /// <summary>
        /// Registry for entities to be processed using the given actor system
        /// </summary>
        /// <param name="actorSystem"></param>
        public ShardedEntityRegistry(ActorSystem actorSystem)
        {
            ActorSystem = actorSystem;

            var persistenceConfig = ActorSystem.Settings.Config
                                    .WithFallback(@"wyvern.persistence {}")
                                    .GetConfig("wyvern.persistence");

            AskTimeout        = persistenceConfig.GetTimeSpan("ask-timeout", 5.0d.seconds(), false);
            MaxNumberOfShards = Math.Max(persistenceConfig.GetInt("max-number-of-shards", 1), 1);
            var role = persistenceConfig.GetString("run-entities-on-role", "");

            Role          = string.IsNullOrWhiteSpace(role) ? Option <string> .None : new Option <string>(role);
            SnapshotAfter = persistenceConfig.GetInt("snapshot-after", 100);

            Sharding         = ClusterSharding.Get(ActorSystem);
            ShardingSettings = ClusterShardingSettings
                               .Create(ActorSystem)
                               .WithRole(Role.Value);

            QueryPluginId = new Option <string>(SqlReadJournal.Identifier);

            var persistence = SqlServerPersistence.Get(ActorSystem);

            EventsByTagQuery = PersistenceQuery.Get(ActorSystem)
                               .ReadJournalFor <SqlReadJournal>(SqlReadJournal.Identifier);
            EventsByPersistenceIdQuery = PersistenceQuery.Get(ActorSystem)
                                         .ReadJournalFor <SqlReadJournal>(SqlReadJournal.Identifier);

            //var journalConfig = persistence.DefaultJournalConfig;
            //var sqlJournal = new SqlServerJournal(journalConfig);

            ExtractShardId = obj =>
            {
                switch (obj)
                {
                case IShardId i:
                    return($"{i.ShardId}");

                case CommandEnvelope commandEnvelope:
                    return(commandEnvelope.EntityId.ToShardId(MaxNumberOfShards));

                default:
                    throw new InvalidOperationException("Cannot derive shard identifier from unknown type");
                }
            };
            ExtractEntityId = obj =>
            {
                switch (obj)
                {
                case CommandEnvelope commandEnvelope:
                    return(($"{commandEnvelope.EntityId}", commandEnvelope.Payload).ToTuple());

                default:
                    throw new InvalidOperationException("Cannot derive entity identifier from unknown type");
                }
            };
        }
コード例 #5
0
 static CoordinatedShutdownShardingSpec()
 {
     SpecConfig = ConfigurationFactory.ParseString(@"
         akka.loglevel = DEBUG
         akka.actor.provider = cluster
         akka.remote.dot-netty.tcp.port = 0")
                  .WithFallback(ClusterSingletonManager.DefaultConfig()
                                .WithFallback(ClusterSharding.DefaultConfig()));
 }
 public IActorRef Start(ActorSystem system, ClusterShardingSettings settings, Props actorProps)
 {
     return(ClusterSharding.Get(system).Start(
                Name,
                actorProps,
                settings.WithRole(Role.IfNoneUnsafe(() => null)),
                new T()
                ));
 }
コード例 #7
0
ファイル: Akka.cs プロジェクト: ronaldharmsen/devsum19
        public static IActorRef CreateOrderShardProxy(this ActorSystem system)
        {
            var sharding = ClusterSharding.Get(system);

            return(sharding.StartProxy(
                       typeName: "order",
                       role: "demo",
                       messageExtractor: new MessageExtractor()));
        }
 public IActorRef Start(ActorSystem system, ClusterShardingSettings settings, Props actorProps)
 {
     return(ClusterSharding.Get(system).Start(
                Name,
                actorProps,
                settings.WithRole("worker"),
                new T()
                ));
 }
コード例 #9
0
        static int Main(string[] args)
        {
            var mongoConnectionString = Environment.GetEnvironmentVariable("MONGO_CONNECTION_STR")?.Trim();

            if (string.IsNullOrEmpty(mongoConnectionString))
            {
                Console.WriteLine("ERROR! MongoDb connection string not provided. Can't start.");
                return(-1);
            }
            else
            {
                Console.WriteLine("Connecting to MongoDb at {0}", mongoConnectionString);
            }

            var config = File.ReadAllText("app.conf");
            var conf   = ConfigurationFactory.ParseString(config).WithFallback(GetMongoHocon(mongoConnectionString))
                         .WithFallback(ClusterSharding.DefaultConfig())
                         .WithFallback(DistributedPubSub.DefaultConfig());

            var actorSystem = ActorSystem.Create("AkkaPricing", conf.BootstrapFromDocker());
            var readJournal = actorSystem.ReadJournalFor <MongoDbReadJournal>(MongoDbReadJournal.Identifier);

            Cluster.Cluster.Get(actorSystem).RegisterOnMemberUp(() =>
            {
                var sharding = ClusterSharding.Get(actorSystem);

                var shardRegion = sharding.Start("priceAggregator",
                                                 s => Props.Create(() => new MatchAggregator(s, readJournal)),
                                                 ClusterShardingSettings.Create(actorSystem),
                                                 new StockShardMsgRouter());

                // used to seed pricing data
                var singleton = ClusterSingletonManager.Props(
                    Props.Create(() => new PriceInitiatorActor(readJournal, shardRegion)),
                    ClusterSingletonManagerSettings.Create(
                        actorSystem.Settings.Config.GetConfig("akka.cluster.price-singleton")));

                var mediator = DistributedPubSub.Get(actorSystem).Mediator;

                foreach (var stock in AvailableTickerSymbols.Symbols)
                {
                    actorSystem.ActorOf(Props.Create(() => new PriceVolumeViewActor(stock, shardRegion, mediator)),
                                        stock + "-view");
                }
            });

            // start Petabridge.Cmd (for external monitoring / supervision)
            var pbm = PetabridgeCmd.Get(actorSystem);

            pbm.RegisterCommandPalette(ClusterCommands.Instance);
            pbm.RegisterCommandPalette(ClusterShardingCommands.Instance);
            pbm.RegisterCommandPalette(RemoteCommands.Instance);
            pbm.Start();

            actorSystem.WhenTerminated.Wait();
            return(0);
        }
コード例 #10
0
        public static ActorSystem Start(string[] args)
        {
            var config = ConfigurationFactory.ParseString(File.ReadAllText("node.hocon"))
                         .WithFallback(ClusterSharding.DefaultConfig())
                         .BootstrapFromDocker();

            actorSystem = ActorSystem.Create("xTreamCacheSystem", config);
            return(actorSystem);
        }
コード例 #11
0
        protected ClusterShardingCustomShardAllocationSpec(ClusterShardingCustomShardAllocationSpecConfig config)
            : base(config, typeof(ClusterShardingCustomShardAllocationSpec))
        {
            _config = config;

            _region = new Lazy <IActorRef>(() => ClusterSharding.Get(Sys).ShardRegion("Entity"));

            _allocator = new Lazy <IActorRef>(() => Sys.ActorOf(Props.Create <Allocator>(), "allocator"));
        }
コード例 #12
0
        protected AggregateClusterTests(AggregateClusterTestConfig config)
            : base(config, typeof(AggregateClusterTests))
        {
            _config         = config;
            _numberOfShards = 32;
            var aggregateManagerName = typeof(TestAggregateManager).Name;

            _aggregateManagerProxy = new Lazy <IActorRef>(() => ClusterSharding.Get(Sys).ShardRegionProxy(aggregateManagerName));
        }
 private void StartShardingWithExtractor1()
 {
     ClusterSharding.Get(Sys).Start(
         typeName: TypeName,
         entityProps: Props.Create(() => new TestEntity(null)),
         settings: ClusterShardingSettings.Create(Sys).WithRememberEntities(true).WithRole("sharding"),
         extractEntityId: extractEntityId,
         extractShardId: extractShardId1);
 }
コード例 #14
0
 private void StartSharding()
 {
     ClusterSharding.Get(Sys).Start(
         typeName: "Entity",
         entityProps: Props.Create <Entity>(),
         settings: ClusterShardingSettings.Create(Sys),
         extractEntityId: extractEntityId,
         extractShardId: extractShardId);
 }
 private void StartShardingWithExtractor2(ActorSystem sys, IActorRef probe)
 {
     ClusterSharding.Get(sys).Start(
         typeName: TypeName,
         entityProps: Props.Create(() => new TestEntity(probe)),
         settings: ClusterShardingSettings.Create(Sys).WithRememberEntities(true).WithRole("sharding"),
         extractEntityId: extractEntityId,
         extractShardId: extractShardId2);
 }
コード例 #16
0
 private void StartShard()
 {
     ClusterSharding.Get(Sys).Start(
         typeName: ShardTypeName,
         entityProps: Props.Create <ShardedActor>(),
         settings: ClusterShardingSettings.Create(Sys).WithRole("shard"),
         extractEntityId: extractEntityId,
         extractShardId: extractShardId);
 }
コード例 #17
0
        static int Main(string[] args)
        {
            var config = File.ReadAllText("app.conf");
            var conf   = ConfigurationFactory.ParseString(config);

            var actorSystem = ActorSystem.Create("AkkaTrader", conf.BoostrapApplication(new AppBootstrapConfig(true, true)));

            var sharding = ClusterSharding.Get(actorSystem);


            var shardRegion = sharding.Start("priceAggregator",
                                             s => Props.Create(() => new MatchAggregator(s)),
                                             ClusterShardingSettings.Create(actorSystem),
                                             new StockShardMsgRouter());

            var priceInitiatorActor = actorSystem.ActorOf(ClusterSingletonManager.Props(Props.Create(() => new PriceInitiatorActor(shardRegion)),
                                                                                        ClusterSingletonManagerSettings.Create(actorSystem).WithRole("pricing-engine").WithSingletonName("priceInitiator")), "priceInitiator");

            var clientHandler =
                actorSystem.ActorOf(Props.Create(() => new ClientHandlerActor(shardRegion)), "subscriptions");

            // make ourselves available to ClusterClient at /user/subscriptions
            ClusterClientReceptionist.Get(actorSystem).RegisterService(clientHandler);

            Cluster.Cluster.Get(actorSystem).RegisterOnMemberUp(() =>
            {
                foreach (var ticker in AvailableTickerSymbols.Symbols)
                {
                    shardRegion.Tell(new Ping(ticker));
                }
            });

            // start Petabridge.Cmd (for external monitoring / supervision)
            var pbm = PetabridgeCmd.Get(actorSystem);

            void RegisterPalette(CommandPaletteHandler h)
            {
                if (pbm.RegisterCommandPalette(h))
                {
                    Console.WriteLine("Petabridge.Cmd - Registered {0}", h.Palette.ModuleName);
                }
                else
                {
                    Console.WriteLine("Petabridge.Cmd - DID NOT REGISTER {0}", h.Palette.ModuleName);
                }
            }

            RegisterPalette(ClusterCommands.Instance);
            RegisterPalette(RemoteCommands.Instance);
            RegisterPalette(ClusterShardingCommands.Instance);
            RegisterPalette(new PriceCommands(shardRegion));
            pbm.Start();

            actorSystem.WhenTerminated.Wait();
            return(0);
        }
コード例 #18
0
 static PersistentShardSpec()
 {
     SpecConfig = ConfigurationFactory.ParseString(@"
         akka.loglevel = DEBUG
         akka.actor.provider = cluster
         akka.persistence.journal.plugin = ""akka.persistence.journal.inmem""
         akka.remote.dot-netty.tcp.port = 0")
                  .WithFallback(ClusterSingletonManager.DefaultConfig()
                                .WithFallback(ClusterSharding.DefaultConfig()));
 }
コード例 #19
0
 public AkkaClient()
 {
     _system           = ActorSystem.Create(SystemConfigurationHelper.ClusterName, SystemConfigurationHelper.GetConfig(0, Role));
     _automaticCluster = new AutomaticCluster(_system);
     _automaticCluster.Join();
     TargetServer = ClusterSharding.Get(_system).StartProxy(
         typeName: "stuffer",
         role: null,
         messageExtractor: GetMessageExtractor());
 }
コード例 #20
0
        public ShardedSubscriptionManager(ActorSystem actorSystem)
        {
            var settings = ClusterShardingSettings.Create(actorSystem);

            shardedSubscriptionActorRef = ClusterSharding.Get(actorSystem).Start(
                typeName: "SubscriptionActor",
                entityProps: Props.Create <SubscriptionActor>(),
                settings: settings,
                messageExtractor: new SubscriptionMessageExtractor());
        }
コード例 #21
0
        public void GetShardTypeNames_must_contain_started_shards_when_started_2_shards()
        {
            Cluster.Get(Sys).Join(Cluster.Get(Sys).SelfAddress);
            var settings = ClusterShardingSettings.Create(Sys);

            ClusterSharding.Get(Sys).Start("type1", EchoActor.Props(this), settings, ExtractEntityId, ExtractShardId);
            ClusterSharding.Get(Sys).Start("type2", EchoActor.Props(this), settings, ExtractEntityId, ExtractShardId);

            ClusterSharding.Get(Sys).ShardTypeNames.ShouldBeEquivalentTo(new string[] { "type1", "type2" });
        }
コード例 #22
0
        static int Main(string[] args)
        {
            var sqlConnectionString = Environment.GetEnvironmentVariable("SQL_CONNECTION_STR");
            var sqlHostName         = Environment.GetEnvironmentVariable("SQL_HOSTNAME");

            if (string.IsNullOrEmpty(sqlConnectionString) || string.IsNullOrEmpty(sqlHostName))
            {
                Console.WriteLine("ERROR! No SQL Connection String specified. Exiting with code -1");
                return(-1);
            }

            //var hostIp = Dns.GetHostEntry(sqlHostName);
            //sqlConnectionString = sqlConnectionString.Replace("{HOSTNAME}", hostIp.AddressList.First().ToString());
            Console.WriteLine("Connecting to SQL Server via {0}", sqlConnectionString);

            var config = ConfigurationFactory.ParseString(File.ReadAllText("sharding.hocon"));

            var sqlHocon = "akka.persistence.journal.sql-server.connection-string = \"" + sqlConnectionString + "\"" +
                           Environment.NewLine +
                           "akka.persistence.snapshot-store.sql-server.connection-string = \"" + sqlConnectionString +
                           "\"";

            Console.WriteLine("Using SQL Hocon:" + Environment.NewLine + " {0}", sqlHocon);

            var sqlConnectionConfig = ConfigurationFactory.ParseString(sqlHocon)
                                      .WithFallback(config);

            var actorSystem = ActorSystem.Create("ShardFight", sqlConnectionConfig.BootstrapFromDocker().WithFallback(ClusterSharding.DefaultConfig()));

            ICancelable shardTask = null;

            Cluster.Get(actorSystem).RegisterOnMemberUp(() =>
            {
                var sharding            = ClusterSharding.Get(actorSystem);
                IActorRef myShardRegion = sharding.Start("entities", str => Props.Create(() => new PersistentEntityActor(str)),
                                                         ClusterShardingSettings.Create(actorSystem).WithRole("shard"), new FuberMessageExtractor());

                shardTask = actorSystem.Scheduler.Advanced.ScheduleRepeatedlyCancelable(TimeSpan.FromMilliseconds(250),
                                                                                        TimeSpan.FromMilliseconds(250),
                                                                                        () =>
                {
                    myShardRegion.Tell(new FuberEnvelope(ThreadLocalRandom.Current.Next(0, 100000).ToString(), ThreadLocalRandom.Current.Next().ToString()));
                });
            });

            var pbm = PetabridgeCmd.Get(actorSystem);

            pbm.RegisterCommandPalette(ClusterCommands.Instance);         // enable cluster management commands
            pbm.RegisterCommandPalette(ClusterShardingCommands.Instance); //enable cluster.sharding management commands
            pbm.Start();

            actorSystem.WhenTerminated.Wait();
            shardTask?.Cancel(); // should already be cancelled
            return(0);
        }
コード例 #23
0
        private Actors(Config config)
        {
            _system = ActorSystem.Create(Constants.SystemName, config);

            var sharding = ClusterSharding.Get(_system);

            CustomerProxy = sharding.StartProxy(
                typeName: Customer.TypeName,
                role: Constants.ClusterNodeRoleName,
                messageExtractor: new MessageExtractor());
        }
コード例 #24
0
        private void ConfigureSharding()
        {
            var system = Context.System;

            // register actor type as a sharded entity
            region = ClusterSharding.Get(system).Start(
                typeName: "aggregate",
                entityProps: Props.Create <AggregateActor>(),
                settings: ClusterShardingSettings.Create(system),
                messageExtractor: new MessageExtractor());
        }
コード例 #25
0
        private void StartSharding(ActorSystem sys, IActorRef probe)
        {
            var allocationStrategy = new LeastShardAllocationStrategy(2, 1);

            ClusterSharding.Get(sys).Start(
                typeName: "Entity",
                entityProps: Props.Create(() => new TestEntity(probe)),
                settings: ClusterShardingSettings.Create(Sys).WithRememberEntities(true),
                extractEntityId: extractEntityId,
                extractShardId: extractShardId);
        }
コード例 #26
0
 private void StartSharding()
 {
     ClusterSharding.Get(Sys).Start(
         typeName: "Entity",
         entityProps: Props.Create <Entity>(),
         settings: ClusterShardingSettings.Create(Sys),
         extractEntityId: extractEntityId,
         extractShardId: extractShardId,
         allocationStrategy: new TestAllocationStrategy(_allocator.Value),
         handOffStopMessage: PoisonPill.Instance);
 }
コード例 #27
0
        public static IActorRef BootstrapShard <T>(this ActorSystem system, string role = null) where T : ActorBase
        {
            var clusterSharding = ClusterSharding.Get(system);

            return(clusterSharding.Start(
                       typeName: typeof(T).Name,
                       entityProps: Props.Create <T>(),
                       settings: ClusterShardingSettings.Create(system)
                       .WithRole(role),
                       messageExtractor: new CustomMessageExtractor()));
        }
コード例 #28
0
        public AtomDocumentShardedActorRefFactory(ActorSystem actorSystem)
        {
            this.actorSystem = actorSystem;

            var settings = ClusterShardingSettings.Create(actorSystem);

            ClusterSharding.Get(actorSystem).Start(
                typeName: "AtomFeedActor",
                entityProps: Props.Create <AtomDocumentActor>(),
                settings: settings,
                messageExtractor: new AtomDocumentShardDataMessageExtractor());
        }
コード例 #29
0
        public void Should_load_DData_serializers_when_enabled()
        {
            ClusterSharding.Get(Sys);

            var rmSerializer = Sys.Serialization.FindSerializerFor(WriteAck.Instance);

            rmSerializer.Should().BeOfType <ReplicatorMessageSerializer>();

            var rDSerializer = Sys.Serialization.FindSerializerFor(ORDictionary <string, GSet <string> > .Empty);

            rDSerializer.Should().BeOfType <ReplicatedDataSerializer>();
        }
コード例 #30
0
        public void Handle(DummyRequest req)
        {
            _origonalActor = Sender;
            var shardRegion = ClusterSharding.Get(Context.System).ShardRegion("testregion");

            var message  = new Server.TestEntity.StreamedDataRequest(1000, 100000);
            var envelope = new Server.Envelope(1, message);

            shardRegion.Tell(envelope);

            _log.Info("Handled DummyRequest");
        }