public override void Register <TE>(Func <ReadSideProcessor <TE> > processorFactory) { if (!Config.Role.ForAll(Cluster.Get(System).SelfRoles.Contains)) { return; } ReadSideProcessor <TE> dummyProcessor; try { dummyProcessor = processorFactory(); } catch (Exception) { throw new InvalidOperationException( "Cannot create instance of ReadSideProcessor" ); } var readSideName = (Name.HasValue ? (Name.Value + "-") : "") + dummyProcessor.ReadSideName; var encodedReadSideName = WebUtility.UrlEncode(readSideName); var tags = dummyProcessor.AggregateTags; var entityIds = tags.Select(x => x.Tag); var globalPrepareTask = ClusterStartupTask.Apply( System, $"readSideGlobalPrepare-{encodedReadSideName}", () => processorFactory().BuildHandler().GlobalPrepare(), Config.GlobalPrepareTimeout, Config.Role, Config.MinBackoff, Config.MaxBackoff, Config.RandomBackoffFactor ); var readSideProps = ReadSideActor.Props( Config, globalPrepareTask, Registry.EventStream <TE>, processorFactory ); var shardingSettings = ClusterShardingSettings.Create(System).WithRole(Config.Role.OrElse("")); new ClusterDistributionExtensionProvider.ClusterDistribution(System).Start( readSideName, readSideProps, entityIds.ToArray(), new ClusterDistributionSettings(System, shardingSettings) ); }
public static Props Props <TE>( ReadSideConfig config, ClusterStartupTask globalPrepareTask, Func <AggregateEventTag, Offset, Source <EventStreamElement <TE>, NotUsed> > eventStreamFactory, Func <ReadSideProcessor <TE> > processor ) where TE : AggregateEvent <TE> { return(Akka.Actor.Props.Create( () => new ReadSideActor <TE>( config, globalPrepareTask, eventStreamFactory, processor ) )); }