public PulsarClientActor(ClientConfigurationData conf, IActorRef cnxPool, IActorRef txnCoordinator, IActorRef lookup, IActorRef idGenerator) { if (conf == null || string.IsNullOrWhiteSpace(conf.ServiceUrl)) { throw new PulsarClientException.InvalidConfigurationException("Invalid client configuration"); } _tcClient = txnCoordinator; _log = Context.GetLogger(); Auth = conf; _conf = conf; _clientClock = conf.Clock; conf.Authentication.Start(); _cnxPool = cnxPool; _lookup = lookup; _producers = new HashSet <IActorRef>(); _consumers = new HashSet <IActorRef>(); _state = State.Open; Receive <AddProducer>(m => _producers.Add(m.Producer)); Receive <UpdateServiceUrl>(m => UpdateServiceUrl(m.ServiceUrl)); Receive <AddConsumer>(m => _consumers.Add(m.Consumer)); Receive <GetClientState>(_ => Sender.Tell((int)_state)); Receive <CleanupConsumer>(m => _consumers.Remove(m.Consumer)); Receive <CleanupProducer>(m => _producers.Remove(m.Producer)); Receive <GetTcClient>(_ => { Sender.Tell(new TcClient(_tcClient)); }); }
internal SocketClient(ClientConfigurationData conf, DnsEndPoint server, string hostName, ILoggingAdapter logger) { _server = server; if (conf.ClientCertificates != null) { _clientCertificates = conf.ClientCertificates; } if (conf.Authentication is AuthenticationTls tls) { _clientCertificates = tls.AuthData.TlsCertificates; } if (conf.TrustedCertificateAuthority != null) { _trustedCertificateAuthority = conf.TrustedCertificateAuthority; } _encrypt = conf.UseTls; _serviceUrl = conf.ServiceUrl; _clientConfiguration = conf; _logger = logger; _targetServerName = hostName; //_heartbeat.Start(); //_connectonId = $"{_networkstream.}"; }
/// <summary> /// Use case: publish single message to multiple topics! /// Example: Food Ordered broadcast message to account, audit, chef, driver topics /// </summary> /// <param name="schema"></param> /// <param name="configuration"></param> /// <param name="producerConfigurations"></param> /// <param name="title">Internally used by PulsarSharp to prevent duplication</param> public NewProducerBroadcastGroup(ISchema <T> schema, ClientConfigurationData configuration, ImmutableHashSet <ProducerConfigurationData> producerConfigurations, string title) { Schema = schema; Configuration = configuration; ProducerConfigurations = producerConfigurations; Title = title; }
protected ProducerActorBase(IActorRef client, IActorRef lookup, IActorRef cnxPool, string topic, ProducerConfigurationData conf, ISchema <T> schema, ProducerInterceptors <T> interceptors, ClientConfigurationData configurationData) { ClientConfiguration = configurationData; Client = client; _topic = topic; if (conf.BatchingEnabled && conf.AckReceivedListerner == null) { conf.AckReceivedListerner = (acked) => { Context.System.Log.Info($"AckReceived(ledger-id:{acked.LedgerId}, entery-id:{acked.EntryId}, sequence-id:{acked.SequenceId}, highest-sequence-id:{acked.HighestSequenceId})"); }; } Conf = conf; Schema = schema; Interceptors = interceptors; SchemaCache = new Dictionary <SchemaHash, byte[]>(); if (!conf.MultiSchema) { _multiSchemaMode = MultiSchemaMode.Disabled; } var pName = ProducerName().GetAwaiter().GetResult(); State = new HandlerState(lookup, cnxPool, topic, Context.System, pName); }
public PulsarSourceActor(ClientConfigurationData client, ReaderConfigurationData <T> readerConfiguration, IActorRef clientActor, IActorRef lookup, IActorRef cnxPool, IActorRef generator, long fromOffset, long toOffset, bool isLive, ISchema <T> schema) { _scheduler = Context.System.Scheduler.Advanced; _toOffset = toOffset; _parent = Context.Parent; _lastEventMessageOffset = fromOffset; var topicName = TopicName.Get(readerConfiguration.TopicName); IActorRef stateA = Context.ActorOf(Props.Create(() => new ConsumerStateActor()), $"StateActor{Guid.NewGuid()}"); var subscription = "player-" + ConsumerName.Sha1Hex(Guid.NewGuid().ToString()).Substring(0, 10); if (!string.IsNullOrWhiteSpace(readerConfiguration.SubscriptionRolePrefix)) { subscription = readerConfiguration.SubscriptionRolePrefix + "-" + subscription; } ConsumerConfigurationData <T> consumerConfiguration = new ConsumerConfigurationData <T>(); consumerConfiguration.TopicNames.Add(readerConfiguration.TopicName); consumerConfiguration.SubscriptionName = subscription; consumerConfiguration.SubscriptionType = SubType.Exclusive; consumerConfiguration.SubscriptionMode = SubscriptionMode.NonDurable; consumerConfiguration.ReceiverQueueSize = readerConfiguration.ReceiverQueueSize; consumerConfiguration.ReadCompacted = readerConfiguration.ReadCompacted; consumerConfiguration.StartMessageId = readerConfiguration.StartMessageId; if (readerConfiguration.ReaderName != null) { consumerConfiguration.ConsumerName = readerConfiguration.ReaderName; } if (readerConfiguration.ResetIncludeHead) { consumerConfiguration.ResetIncludeHead = true; } consumerConfiguration.CryptoFailureAction = readerConfiguration.CryptoFailureAction; if (readerConfiguration.CryptoKeyReader != null) { consumerConfiguration.CryptoKeyReader = readerConfiguration.CryptoKeyReader; } if (readerConfiguration.KeyHashRanges != null) { consumerConfiguration.KeySharedPolicy = KeySharedPolicy.StickyHashRange().GetRanges(readerConfiguration.KeyHashRanges.ToArray()); } var partitionIdx = TopicName.GetPartitionIndex(readerConfiguration.TopicName); var consumerId = generator.Ask <long>(NewConsumerId.Instance).GetAwaiter().GetResult(); _child = Context.ActorOf(Props.Create(() => new ConsumerActor <T>(consumerId, stateA, clientActor, lookup, cnxPool, generator, readerConfiguration.TopicName, consumerConfiguration, Context.System.Scheduler.Advanced, partitionIdx, true, readerConfiguration.StartMessageId, readerConfiguration.StartMessageFromRollbackDurationInSec, schema, true, client))); _child.Tell(Connect.Instance); if (isLive) { LiveConsume(); } else { Consume(); } }
private PulsarSystem(ActorSystem actorSystem, PulsarClientConfigBuilder confBuilder) { _conf = confBuilder.ClientConfigurationData; var conf = _conf; _actorSystem = actorSystem; _conf = conf; _cnxPool = _actorSystem.ActorOf(ConnectionPool.Prop(conf), "ConnectionPool"); _generator = _actorSystem.ActorOf(IdGeneratorActor.Prop(), "IdGenerator"); _lookup = _actorSystem.ActorOf(BinaryProtoLookupService.Prop(_cnxPool, _generator, conf.ServiceUrl, conf.ListenerName, conf.UseTls, conf.MaxLookupRequest, conf.OperationTimeout), "BinaryProtoLookupService"); if (conf.EnableTransaction) { _tcClient = _actorSystem.ActorOf(TransactionCoordinatorClient.Prop(_lookup, _cnxPool, _generator, conf)); var cos = _tcClient.Ask <AskResponse>("Start").GetAwaiter().GetResult(); if (cos.Failed) { throw cos.Exception; } if ((int)cos.Data <= 0) { throw new Exception($"Tranaction Coordinator has '{cos}' transaction handler"); } } _client = _actorSystem.ActorOf(Props.Create <PulsarClientActor>(conf, _cnxPool, _tcClient, _lookup, _generator), "PulsarClient"); _lookup.Tell(new SetClient(_client)); }
public EventSourceTests(ITestOutputHelper output, PulsarStandaloneClusterFixture fixture) { _output = output; _client = fixture.Client; _pulsarSystem = fixture.PulsarSystem; _clientConfigurationData = fixture.ClientConfigurationData; }
public ConnectionHandler(ClientConfigurationData conf, HandlerState state, Backoff backoff, IActorRef connection) { _state = state; _connection = connection; _backoff = backoff; _log = Context.System.Log; _actorContext = Context; _conf = conf; Listening(); }
private PulsarSystem(PulsarClientConfigBuilder confBuilder, Action logSetup, Config confg) { _conf = confBuilder.ClientConfigurationData; var conf = _conf; var logging = logSetup ?? _logSetup; logging(); _conf = conf; var config = confg ?? ConfigurationFactory.ParseString(@" akka { loglevel = DEBUG log-config-on-start = on loggers=[""Akka.Logger.NLog.NLogLogger, Akka.Logger.NLog""] actor { debug { receive = on autoreceive = on lifecycle = on event-stream = on unhandled = on } } coordinated-shutdown { exit-clr = on } }" ); _actorSystem = ActorSystem.Create("Pulsar", config); _cnxPool = _actorSystem.ActorOf(ConnectionPool.Prop(conf), "ConnectionPool"); _generator = _actorSystem.ActorOf(IdGeneratorActor.Prop(), "IdGenerator"); _lookup = _actorSystem.ActorOf(BinaryProtoLookupService.Prop(_cnxPool, _generator, conf.ServiceUrl, conf.ListenerName, conf.UseTls, conf.MaxLookupRequest, conf.OperationTimeout), "BinaryProtoLookupService"); if (conf.EnableTransaction) { _tcClient = _actorSystem.ActorOf(TransactionCoordinatorClient.Prop(_lookup, _cnxPool, _generator, conf)); var cos = _tcClient.Ask <AskResponse>("Start").GetAwaiter().GetResult(); if (cos.Failed) { throw cos.Exception; } if ((int)cos.Data <= 0) { throw new Exception($"Tranaction Coordinator has '{cos}' transaction handler"); } } _client = _actorSystem.ActorOf(Props.Create(() => new PulsarClientActor(conf, _cnxPool, _tcClient, _lookup, _generator)), "PulsarClient"); _lookup.Tell(new SetClient(_client)); }
public PulsarClient(IActorRef client, IActorRef lookup, IActorRef cnxPool, IActorRef idGenerator, ClientConfigurationData clientConfiguration, ActorSystem actorSystem, IActorRef transactionCoordinatorClient) { _generator = idGenerator; _client = client; _clientConfigurationData = clientConfiguration; _actorSystem = actorSystem; _transactionCoordinatorClient = transactionCoordinatorClient; _log = actorSystem.Log; _lookup = lookup; _cnxPool = cnxPool; }
public ConnectionPool(ClientConfigurationData conf) { _context = Context; _log = Context.GetLogger(); _clientConfig = conf; _maxConnectionsPerHosts = conf.ConnectionsPerBroker; //_isSniProxy = _clientConfig.UseTls && _clientConfig.ProxyProtocol != null && !string.IsNullOrWhiteSpace(_clientConfig.ProxyServiceUrl); _pool = new Dictionary <EndPoint, Dictionary <int, ConnectionOpened> >(); Listen(); }
public EventsByTopic(string tenant, string ns, string topic, long fromMessageId, long toMessageId, string adminUrl, ReaderConfigurationData <T> configuration, ClientConfigurationData clientConfiguration) { Tenant = tenant; Namespace = ns; Topic = topic; FromMessageId = fromMessageId; ToMessageId = toMessageId; Source = SourceType.Pulsar; AdminUrl = adminUrl; Configuration = configuration; ClientConfiguration = clientConfiguration; }
internal StartReplayTopic(ClientConfigurationData clientConfigurationData, ReaderConfigurationData <T> readerConfigurationData, string adminUrl, long @from, long to, long max, Tag tag, bool tagged, SourceType source) { ClientConfigurationData = clientConfigurationData; ReaderConfigurationData = readerConfigurationData; From = @from; To = to; Max = max; Tag = tag; Tagged = tagged; Source = source; AdminUrl = adminUrl; }
public ReaderSourceBuilder <T> Reader <T>(ClientConfigurationData clientConfiguration, ReaderConfigBuilder <T> readerConfigBuilder, ISchema <T> schema) { if (schema == null) { throw new NullReferenceException(nameof(schema)); } if (readerConfigBuilder == null) { throw new NullReferenceException(nameof(readerConfigBuilder)); } return(new ReaderSourceBuilder <T>(clientConfiguration, schema, _actorSystem, _client, _lookup, _cnxPool, _generator, _tenant, _namespace, _topic, _fromMessageId, _toMessageId, _brokerWebServiceUrl, readerConfigBuilder)); }
private void SetupSystem() { var client = new PulsarClientConfigBuilder(); var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var config = GetIConfigurationRoot(path); var clienConfigSetting = config.GetSection("client"); var serviceUrl = clienConfigSetting.GetSection("service-url").Value; var webUrl = clienConfigSetting.GetSection("web-url").Value; var authPluginClassName = clienConfigSetting.GetSection("authPluginClassName").Value; var authParamsString = clienConfigSetting.GetSection("authParamsString").Value; var authCertPath = clienConfigSetting.GetSection("authCertPath").Value; var connectionsPerBroker = int.Parse(clienConfigSetting.GetSection("connections-per-broker").Value); var statsInterval = int.Parse(clienConfigSetting.GetSection("stats-interval").Value); var operationTime = int.Parse(clienConfigSetting.GetSection("operationTime").Value); var allowTlsInsecureConnection = bool.Parse(clienConfigSetting.GetSection("allowTlsInsecureConnection").Value); var enableTls = bool.Parse(clienConfigSetting.GetSection("enableTls").Value); var enableTxn = bool.Parse(clienConfigSetting.GetSection("enableTransaction").Value); var dedicatedConnection = bool.Parse(clienConfigSetting.GetSection("userDedicatedConnection").Value); client.EnableTransaction(enableTxn); if (operationTime > 0) { client.OperationTimeout(TimeSpan.FromMilliseconds(operationTime)); } if (!string.IsNullOrWhiteSpace(authCertPath)) { client.AddTrustedAuthCert(new X509Certificate2(File.ReadAllBytes(authCertPath))); } if (!string.IsNullOrWhiteSpace(authPluginClassName) && !string.IsNullOrWhiteSpace(authParamsString)) { client.Authentication(authPluginClassName, authParamsString); } client.ServiceUrl(serviceUrl); client.WebUrl(webUrl); client.ConnectionsPerBroker(connectionsPerBroker); client.StatsInterval(statsInterval); client.AllowTlsInsecureConnection(allowTlsInsecureConnection); client.EnableTls(enableTls); var system = PulsarSystem.GetInstance(client); Client = system.NewClient(); PulsarSystem = system; ClientConfigurationData = client.ClientConfigurationData; }
public ReaderSourceBuilder(ClientConfigurationData clientConfiguration, ISchema <T> schema, ActorSystem actorSystem, IActorRef client, IActorRef lookup, IActorRef cnxPool, IActorRef generator, string tenant, string @namespace, string topic, long fromMessageId, long toMessageId, string brokerWebServiceUrl, ReaderConfigBuilder <T> readerConfigBuilder) { _clientConfiguration = clientConfiguration; _schema = schema; _client = client; _lookup = lookup; _cnxPool = cnxPool; _generator = generator; _actorSystem = actorSystem; _fromMessageId = fromMessageId; _toMessageId = toMessageId; _tenant = tenant; _namespace = @namespace; _topic = topic; _brokerWebServiceUrl = brokerWebServiceUrl; _conf = readerConfigBuilder; }
public TransactionCoordinatorClient(IActorRef lookup, IActorRef cnxPool, IActorRef idGenerator, ClientConfigurationData conf) { _cnxPool = cnxPool; _lookup = lookup; _generator = idGenerator; _clientConfigurationData = conf; _log = Context.GetLogger(); ReceiveAsync <string>(async st => { _sender = Sender; if (st.Equals("Start")) { await StartCoordinator(); } }); ReceiveAny(_ => Stash.Stash()); }
public static Props Prop(ClientConfigurationData client, ReaderConfigurationData <T> readerConfiguration, IActorRef clientActor, IActorRef lookup, IActorRef cnxPool, IActorRef generator, long fromOffset, long toOffset, bool isLive, Tag tag, ISchema <T> schema) { return(Props.Create(() => new PulsarTaggedSourceActor <T>(client, readerConfiguration, clientActor, lookup, cnxPool, generator, fromOffset, toOffset, isLive, tag, schema))); }
public ReaderActor(long consumerId, IActorRef stateActor, IActorRef client, IActorRef lookup, IActorRef cnxPool, IActorRef idGenerator, ReaderConfigurationData <T> readerConfiguration, IAdvancedScheduler listenerExecutor, ISchema <T> schema, ClientConfigurationData clientConfigurationData) { _generator = idGenerator; var subscription = "reader-" + ConsumerName.Sha1Hex(Guid.NewGuid().ToString()).Substring(0, 10); if (!string.IsNullOrWhiteSpace(readerConfiguration.SubscriptionRolePrefix)) { subscription = readerConfiguration.SubscriptionRolePrefix + "-" + subscription; } ConsumerConfigurationData <T> consumerConfiguration = new ConsumerConfigurationData <T>(); consumerConfiguration.TopicNames.Add(readerConfiguration.TopicName); consumerConfiguration.SubscriptionName = subscription; consumerConfiguration.SubscriptionType = SubType.Exclusive; consumerConfiguration.SubscriptionMode = SubscriptionMode.NonDurable; consumerConfiguration.ReceiverQueueSize = readerConfiguration.ReceiverQueueSize; consumerConfiguration.ReadCompacted = readerConfiguration.ReadCompacted; // Reader doesn't need any batch receiving behaviours // disable the batch receive timer for the ConsumerImpl instance wrapped by the ReaderImpl consumerConfiguration.BatchReceivePolicy = _disabledBatchReceivePolicy; if (readerConfiguration.StartMessageId != null) { consumerConfiguration.StartMessageId = (BatchMessageId)readerConfiguration.StartMessageId; } if (readerConfiguration.ReaderName != null) { consumerConfiguration.ConsumerName = readerConfiguration.ReaderName; } if (readerConfiguration.ResetIncludeHead) { consumerConfiguration.ResetIncludeHead = true; } if (readerConfiguration.ReaderListener != null) { var readerListener = readerConfiguration.ReaderListener; consumerConfiguration.MessageListener = new MessageListenerAnonymousInnerClass(Self, readerListener); } consumerConfiguration.CryptoFailureAction = readerConfiguration.CryptoFailureAction; if (readerConfiguration.CryptoKeyReader != null) { consumerConfiguration.CryptoKeyReader = readerConfiguration.CryptoKeyReader; } if (readerConfiguration.KeyHashRanges != null) { consumerConfiguration.KeySharedPolicy = KeySharedPolicy.StickyHashRange().GetRanges(readerConfiguration.KeyHashRanges.ToArray()); } int partitionIdx = TopicName.GetPartitionIndex(readerConfiguration.TopicName); if (consumerConfiguration.ReceiverQueueSize == 0) { _consumer = Context.ActorOf(Props.Create(() => new ZeroQueueConsumer <T>(consumerId, stateActor, client, lookup, cnxPool, _generator, readerConfiguration.TopicName, consumerConfiguration, listenerExecutor, partitionIdx, false, readerConfiguration.StartMessageId, schema, true, clientConfigurationData))); } else { _consumer = Context.ActorOf(Props.Create(() => new ConsumerActor <T>(consumerId, stateActor, client, lookup, cnxPool, _generator, readerConfiguration.TopicName, consumerConfiguration, listenerExecutor, partitionIdx, false, readerConfiguration.StartMessageId, readerConfiguration.StartMessageFromRollbackDurationInSec, schema, true, clientConfigurationData))); } Receive <HasReachedEndOfTopic>(m => { _consumer.Tell(m, Sender); }); Receive <AcknowledgeCumulativeMessage <T> > (m => { _consumer.Tell(m, Sender); }); Receive <Messages.Consumer.Receive> (m => { _consumer.Tell(m, Sender); }); Receive <Connect> (m => { _consumer.Tell(m, Sender); }); Receive <MessageProcessed <T> > (m => { _consumer.Tell(m, Sender); }); Receive <HasMessageAvailable> (m => { _consumer.Tell(m, Sender); }); Receive <GetTopic> (m => { _consumer.Tell(m, Sender); }); Receive <IsConnected> (m => { _consumer.Tell(m, Sender); }); Receive <SeekMessageId> (m => { _consumer.Tell(m, Sender); }); Receive <SeekTimestamp> (m => { _consumer.Tell(m, Sender); }); }
internal ZeroQueueConsumer(long consumerId, IActorRef stateActor, IActorRef client, IActorRef lookup, IActorRef cnxPool, IActorRef idGenerator, string topic, ConsumerConfigurationData <T> conf, IAdvancedScheduler listenerExecutor, int partitionIndex, bool hasParentConsumer, IMessageId startMessageId, ISchema <T> schema, bool createTopicIfDoesNotExist, ClientConfigurationData clientConfiguration) : base(consumerId, stateActor, client, lookup, cnxPool, idGenerator, topic, conf, listenerExecutor, partitionIndex, hasParentConsumer, startMessageId, 0, schema, createTopicIfDoesNotExist, clientConfiguration) { }
public static Props Prop(IActorRef lookup, IActorRef cnxPool, IActorRef idGenerator, ClientConfigurationData conf) { return(Props.Create(() => new TransactionCoordinatorClient(lookup, cnxPool, idGenerator, conf))); }
public PatternMultiTopicsConsumer(Regex topicsPattern, IActorRef stateActor, IActorRef client, IActorRef lookup, IActorRef cnxPool, IActorRef idGenerator, ConsumerConfigurationData <T> conf, ISchema <T> schema, Mode subscriptionMode, ClientConfigurationData clientConfiguration) : base(stateActor, client, lookup, cnxPool, idGenerator, conf, Context.System.Scheduler.Advanced, schema, false, clientConfiguration) { _self = Self; _lookup = lookup; _context = Context; _topicsPattern = topicsPattern; _subscriptionMode = subscriptionMode; if (NamespaceName == null) { NamespaceName = GetNameSpaceFromPattern(topicsPattern); } Condition.CheckArgument(GetNameSpaceFromPattern(topicsPattern).ToString().Equals(NamespaceName.ToString())); _recheckPatternTimeout = Context.System.Scheduler.Advanced.ScheduleOnceCancelable(TimeSpan.FromSeconds(Math.Max(1, Conf.PatternAutoDiscoveryPeriod)), async() => { await TopicReChecker(); }); }
public static Props Prop(ClientConfigurationData conf) { return(Props.Create(() => new ConnectionPool(conf))); }
public static Props Prop(Regex topicsPattern, IActorRef stateActor, IActorRef client, IActorRef lookup, IActorRef cnxPool, IActorRef idGenerator, ConsumerConfigurationData <T> conf, ISchema <T> schema, Mode subscriptionMode, ClientConfigurationData clientConfiguration) { return(Props.Create(() => new PatternMultiTopicsConsumer <T>(topicsPattern, stateActor, client, lookup, cnxPool, idGenerator, conf, schema, subscriptionMode, clientConfiguration))); }
public static ISocketClient CreateClient(ClientConfigurationData conf, DnsEndPoint server, string hostName, ILoggingAdapter logger) { return(new SocketClient(conf, server, hostName, logger)); }
public static Props Prop(ClientConfigurationData conf, HandlerState state, Backoff backoff, IActorRef connection) { return(Props.Create(() => new ConnectionHandler(conf, state, backoff, connection))); }
public MultiTopicsReader(IActorRef state, IActorRef client, IActorRef lookup, IActorRef cnxPool, IActorRef idGenerator, ReaderConfigurationData <T> readerConfiguration, IAdvancedScheduler listenerExecutor, ISchema <T> schema, ClientConfigurationData clientConfigurationData) { _generator = idGenerator; var subscription = "multiTopicsReader-" + ConsumerName.Sha1Hex(Guid.NewGuid().ToString()).Substring(0, 10); if (!string.IsNullOrWhiteSpace(readerConfiguration.SubscriptionRolePrefix)) { subscription = readerConfiguration.SubscriptionRolePrefix + "-" + subscription; } var consumerConfiguration = new ConsumerConfigurationData <T>(); foreach (var topic in readerConfiguration.TopicNames) { consumerConfiguration.TopicNames.Add(topic); } consumerConfiguration.SubscriptionName = subscription; consumerConfiguration.SubscriptionType = SubType.Exclusive; consumerConfiguration.SubscriptionMode = SubscriptionMode.NonDurable; consumerConfiguration.ReceiverQueueSize = readerConfiguration.ReceiverQueueSize; consumerConfiguration.ReadCompacted = readerConfiguration.ReadCompacted; if (readerConfiguration.ReaderListener != null) { var readerListener = readerConfiguration.ReaderListener; consumerConfiguration.MessageListener = new MessageListenerAnonymousInnerClass(Self, readerListener); } if (readerConfiguration.StartMessageId != null) { consumerConfiguration.StartMessageId = (BatchMessageId)readerConfiguration.StartMessageId; } if (readerConfiguration.ReaderName != null) { consumerConfiguration.ConsumerName = readerConfiguration.ReaderName; } if (readerConfiguration.ResetIncludeHead) { consumerConfiguration.ResetIncludeHead = true; } consumerConfiguration.CryptoFailureAction = readerConfiguration.CryptoFailureAction; if (readerConfiguration.CryptoKeyReader != null) { consumerConfiguration.CryptoKeyReader = readerConfiguration.CryptoKeyReader; } if (readerConfiguration.KeyHashRanges != null) { consumerConfiguration.KeySharedPolicy = KeySharedPolicy.StickyHashRange().GetRanges(readerConfiguration.KeyHashRanges.ToArray()); } _consumer = Context.ActorOf(Props.Create(() => new MultiTopicsConsumer <T>(state, client, lookup, cnxPool, _generator, consumerConfiguration, listenerExecutor, schema, true, readerConfiguration.StartMessageId, readerConfiguration.StartMessageFromRollbackDurationInSec, clientConfigurationData))); ReceiveAsync <SubscribeAndCreateTopicsIfDoesNotExist>(async subs => { _sender = Sender; await SubscribeAndCreateTopics(subs); }); ReceiveAsync <Subscribe>(async sub => { _sender = Sender; await SubscribeToTopic(sub); }); Receive <HasReachedEndOfTopic>(m => { _consumer.Tell(m, Sender); }); Receive <AcknowledgeCumulativeMessage <T> >(m => { _consumer.Tell(m, Sender); }); Receive <MessageProcessed <T> >(m => { _consumer.Tell(m, Sender); }); Receive <Messages.Consumer.Receive>(m => { _consumer.Tell(m, Sender); }); Receive <HasMessageAvailable>(m => { _consumer.Tell(m, Sender); }); Receive <GetTopic>(m => { _consumer.Tell(m, Sender); }); Receive <IsConnected>(m => { _consumer.Tell(m, Sender); }); Receive <SeekMessageId>(m => { _consumer.Tell(m, Sender); }); Receive <SeekTimestamp>(m => { _consumer.Tell(m, Sender); }); ReceiveAny(m => { _consumer.Tell(m, Sender); }); }
public PartitionedProducer(IActorRef client, IActorRef lookup, IActorRef cnxPool, IActorRef idGenerator, string topic, ProducerConfigurationData conf, int numPartitions, ISchema <T> schema, ProducerInterceptors <T> interceptors, ClientConfigurationData clientConfiguration) : base(client, lookup, cnxPool, topic, conf, schema, interceptors, clientConfiguration) { _cnxPool = cnxPool; _lookup = lookup; _self = Self; _producers = new List <IActorRef>(); _generator = idGenerator; _context = Context; _producers = new List <IActorRef>(numPartitions); _topicMetadata = new TopicMetadata(numPartitions); _stats = clientConfiguration.StatsIntervalSeconds > 0 ? new ProducerStatsRecorder(Context.System, "PartitionedProducer", topic, conf.MaxPendingMessages) : null; _log = Context.GetLogger(); var maxPendingMessages = Math.Min(conf.MaxPendingMessages, conf.MaxPendingMessagesAcrossPartitions / numPartitions); conf.MaxPendingMessages = maxPendingMessages; switch (conf.MessageRoutingMode) { case MessageRoutingMode.ConsistentHashingMode: _router = Context.System.ActorOf(Props.Empty.WithRouter(new ConsistentHashingGroup()), $"Partition{DateTimeHelper.CurrentUnixTimeMillis()}"); break; case MessageRoutingMode.BroadcastMode: _router = Context.System.ActorOf(Props.Empty.WithRouter(new BroadcastGroup()), $"Partition{DateTimeHelper.CurrentUnixTimeMillis()}"); break; case MessageRoutingMode.RandomMode: _router = Context.System.ActorOf(Props.Empty.WithRouter(new RandomGroup()), $"Partition{DateTimeHelper.CurrentUnixTimeMillis()}"); break; default: _router = Context.System.ActorOf(Props.Empty.WithRouter(new RoundRobinGroup()), $"Partition{DateTimeHelper.CurrentUnixTimeMillis()}"); break; } // start track and auto subscribe partition increasement if (conf.AutoUpdatePartitions) { _partitionsAutoUpdateTimeout = _context.System.Scheduler.ScheduleTellRepeatedlyCancelable(TimeSpan.FromSeconds(conf.AutoUpdatePartitionsIntervalSeconds), TimeSpan.FromSeconds(conf.AutoUpdatePartitionsIntervalSeconds), Self, ExtendTopics.Instance, ActorRefs.NoSender); } Receive <Flush>(_ => { Flush(); }); ReceiveAsync <Connect>(async _ => { await Start().ConfigureAwait(false); }); Receive <TriggerFlush>(_ => { TriggerFlush(); }); ReceiveAsync <ExtendTopics>(async _ => { var t = topic; await OnTopicsExtended(new List <string> { t }); }); ReceiveAsync <InternalSend <T> >(async m => { try { //get excepyion vai out await InternalSend(m.Message); } catch (Exception ex) { Sender.Tell(ex); _log.Error(ex.ToString()); } }); Receive <InternalSendWithTxn <T> >(m => { try { InternalSendWithTxn(m.Message, m.Txn); } catch (Exception ex) { Sender.Tell(ex); _log.Error(ex.ToString()); } }); ReceiveAny(any => _router.Forward(any)); }