public Consumer(IActorRef stateActor, IActorRef consumer, ISchema <T> schema, ConsumerConfigurationData <T> conf) { _stateActor = stateActor; _consumerActor = consumer; _schema = schema; _conf = conf; }
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 async ValueTask <Consumer <T> > DoSingleTopicSubscribe <T>(ConsumerConfigurationData <T> conf, ISchema <T> schema) { var topic = conf.SingleTopic; try { var metadata = await GetPartitionedTopicMetadata(topic).ConfigureAwait(false); if (_actorSystem.Log.IsDebugEnabled) { _actorSystem.Log.Debug($"[{topic}] Received topic metadata. partitions: {metadata.Partitions}"); } IActorRef consumer; var state = _actorSystem.ActorOf(Props.Create(() => new ConsumerStateActor()), $"StateActor{Guid.NewGuid()}"); if (metadata.Partitions > 0) { Condition.CheckArgument(conf.TopicNames.Count == 1, "Should have only 1 topic for partitioned consumer"); // get topic name, then remove it from conf, so constructor will create a consumer with no topic. var cloneConf = conf; var topicName = cloneConf.SingleTopic; cloneConf.TopicNames.Remove(topicName); consumer = _actorSystem.ActorOf(Props.Create <MultiTopicsConsumer <T> >(state, _client, _lookup, _cnxPool, _generator, topicName, conf, _actorSystem.Scheduler.Advanced, schema, true, _clientConfigurationData), $"MultiTopicsConsumer{DateTimeHelper.CurrentUnixTimeMillis()}"); var response = await consumer.Ask <AskResponse>(new Subscribe(topic, metadata.Partitions)).ConfigureAwait(false); if (response.Failed) { await consumer.GracefulStop(TimeSpan.FromSeconds(5)); throw response.Exception; } _client.Tell(new AddConsumer(consumer)); return(new Consumer <T>(state, consumer, schema, conf)); } else { var consumerId = await _generator.Ask <long>(NewConsumerId.Instance).ConfigureAwait(false); var partitionIndex = TopicName.GetPartitionIndex(topic); consumer = _actorSystem.ActorOf(Props.Create(() => new ConsumerActor <T>(consumerId, state, _client, _lookup, _cnxPool, _generator, topic, conf, _actorSystem.Scheduler.Advanced, partitionIndex, false, null, schema, true, _clientConfigurationData))); var response = await consumer.Ask <AskResponse>(Connect.Instance).ConfigureAwait(false); if (response.Failed) { await consumer.GracefulStop(TimeSpan.FromSeconds(5)); throw response.Exception; } _client.Tell(new AddConsumer(consumer)); return(new Consumer <T>(state, consumer, schema, conf)); } } catch (Exception e) { _actorSystem.Log.Error($"[{topic}] Failed to get partitioned topic metadata: {e}"); throw; } }
private async ValueTask <Consumer <T> > Subscribe <T>(ConsumerConfigurationData <T> conf, ISchema <T> schema) { var state = await _client.Ask <int>(GetClientState.Instance).ConfigureAwait(false); if (state != 0) { throw new PulsarClientException.AlreadyClosedException("Client already closed"); } if (conf == null) { throw new PulsarClientException.InvalidConfigurationException("Consumer configuration undefined"); } foreach (var topic in conf.TopicNames) { if (!TopicName.IsValid(topic)) { throw new PulsarClientException.InvalidTopicNameException("Invalid topic name: '" + topic + "'"); } } if (string.IsNullOrWhiteSpace(conf.SubscriptionName)) { throw new PulsarClientException.InvalidConfigurationException("Empty subscription name"); } if (conf.ReadCompacted && (conf.TopicNames.Any(topic => TopicName.Get(topic).Domain != TopicDomain.Persistent) || (conf.SubscriptionType != SubType.Exclusive && conf.SubscriptionType != SubType.Failover))) { throw new PulsarClientException.InvalidConfigurationException("Read compacted can only be used with exclusive or failover persistent subscriptions"); } if (conf.ConsumerEventListener != null && conf.SubscriptionType != SubType.Failover) { throw new PulsarClientException.InvalidConfigurationException("Active consumer listener is only supported for failover subscription"); } if (conf.TopicsPattern != null) { // If use topicsPattern, we should not use topic(), and topics() method. if (conf.TopicNames.Count > 0) { throw new ArgumentException("Topic names list must be null when use topicsPattern"); } return(await PatternTopicSubscribe(conf, schema).ConfigureAwait(false)); } else if (conf.TopicNames.Count == 1) { return(await SingleTopicSubscribe(conf, schema).ConfigureAwait(false)); } else { return(await MultiTopicSubscribe(conf, schema).ConfigureAwait(false)); } }
public ConsumerActorBase(IActorRef stateActor, IActorRef lookup, IActorRef connectionPool, string topic, ConsumerConfigurationData <T> conf, int receiverQueueSize, IAdvancedScheduler listenerExecutor, ISchema <T> schema) { if (conf.Interceptors != null && conf.Interceptors.Count > 0) { Interceptors = new ConsumerInterceptors <T>(Context.System, conf.Interceptors); } StateActor = stateActor; _topic = topic; _consumerName = conf.ConsumerName ?? Utility.ConsumerName.GenerateRandomName(); State = new HandlerState(lookup, connectionPool, topic, Context.System, _consumerName); _log = Context.GetLogger(); MaxReceiverQueueSize = receiverQueueSize; _subscription = conf.SubscriptionName; Conf = conf; Listener = conf.MessageListener; ConsumerEventListener = conf.ConsumerEventListener; IncomingMessages = new BufferBlock <IMessage <T> >(); UnAckedChunckedMessageIdSequenceMap = Context.ActorOf(Tracker.UnAckedChunckedMessageIdSequenceMap.Prop()); ListenerExecutor = listenerExecutor; Schema = schema; if (conf.BatchReceivePolicy != null) { var userBatchReceivePolicy = conf.BatchReceivePolicy; if (userBatchReceivePolicy.MaxNumMessages > MaxReceiverQueueSize) { BatchReceivePolicy = new BatchReceivePolicy.Builder().MaxNumMessages(MaxReceiverQueueSize).MaxNumBytes(userBatchReceivePolicy.MaxNumBytes).Timeout((int)userBatchReceivePolicy.TimeoutMs).Build(); _log.Warning($"BatchReceivePolicy maxNumMessages: {userBatchReceivePolicy.MaxNumMessages} is greater than maxReceiverQueueSize: {MaxReceiverQueueSize}, reset to maxReceiverQueueSize. batchReceivePolicy: {BatchReceivePolicy}"); } else if (userBatchReceivePolicy.MaxNumMessages <= 0 && userBatchReceivePolicy.MaxNumBytes <= 0) { BatchReceivePolicy = new BatchReceivePolicy.Builder().MaxNumMessages(BatchReceivePolicy.DefaultPolicy.MaxNumMessages).MaxNumBytes(BatchReceivePolicy.DefaultPolicy.MaxNumBytes).Timeout((int)userBatchReceivePolicy.TimeoutMs).Build(); _log.Warning("BatchReceivePolicy maxNumMessages: {} or maxNumBytes: {} is less than 0. " + "Reset to DEFAULT_POLICY. batchReceivePolicy: {}", userBatchReceivePolicy.MaxNumMessages, userBatchReceivePolicy.MaxNumBytes, BatchReceivePolicy.ToString()); } else { BatchReceivePolicy = conf.BatchReceivePolicy; } } else { BatchReceivePolicy = BatchReceivePolicy.DefaultPolicy; } if (BatchReceivePolicy.TimeoutMs > 0) { //BatchReceiveTimeout = ListenerExecutor.ScheduleOnceCancelable(TimeSpan.FromMilliseconds(TimeUnit.MILLISECONDS.ToMilliseconds(BatchReceivePolicy.TimeoutMs)), PendingBatchReceiveTask); } _stateUpdater = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5), Self, SendState.Instance, ActorRefs.NoSender); }
private async ValueTask <Consumer <T> > PatternTopicSubscribe <T>(ConsumerConfigurationData <T> conf, ISchema <T> schema) { var regex = conf.TopicsPattern.ToString(); var subscriptionMode = ConvertRegexSubscriptionMode(conf.RegexSubscriptionMode); var destination = TopicName.Get(regex); var namespaceName = destination.NamespaceObject; IActorRef consumer = null; try { var ask = await _lookup.Ask <AskResponse>(new GetTopicsUnderNamespace(namespaceName, subscriptionMode.Value)).ConfigureAwait(false); if (ask.Failed) { throw ask.Exception; } var result = ask.ConvertTo <GetTopicsUnderNamespaceResponse>(); var topics = result.Topics; if (_actorSystem.Log.IsDebugEnabled) { _actorSystem.Log.Debug($"Get topics under namespace {namespaceName}, topics.size: {topics.Count}"); topics.ForEach(topicName => _actorSystem.Log.Debug($"Get topics under namespace {namespaceName}, topic: {topicName}")); } var topicsList = TopicsPatternFilter(topics, conf.TopicsPattern); topicsList.ToList().ForEach(x => conf.TopicNames.Add(x)); var state = _actorSystem.ActorOf(Props.Create(() => new ConsumerStateActor()), $"StateActor{Guid.NewGuid()}"); consumer = _actorSystem.ActorOf(PatternMultiTopicsConsumer <T> .Prop(conf.TopicsPattern, state, _client, _lookup, _cnxPool, _generator, conf, schema, subscriptionMode.Value, _clientConfigurationData), $"MultiTopicsConsumer{DateTimeHelper.CurrentUnixTimeMillis()}"); var response = await consumer.Ask <AskResponse>(new SubscribeAndCreateTopicsIfDoesNotExist(conf.TopicNames.ToList(), true)).ConfigureAwait(false); if (response.Failed) { await consumer.GracefulStop(TimeSpan.FromSeconds(5)); throw response.Exception; } _client.Tell(new AddConsumer(consumer)); return(new Consumer <T>(state, consumer, schema, conf)); } catch (Exception e) { if (consumer != null) { await consumer.GracefulStop(TimeSpan.FromSeconds(5)); } _actorSystem.Log.Warning($"[{namespaceName}] Failed to get topics under namespace"); throw e; } }
public NegativeAcksTracker(ConsumerConfigurationData <T> conf, IActorRef consumer, IActorRef unack) { _nackedMessages = new Dictionary <IMessageId, long>(); _log = Context.GetLogger(); _self = Self; _consumer = consumer; _nackDelayMs = Math.Max(conf.NegativeAckRedeliveryDelayMs, MinNackDelayMs); _timerIntervalMs = _nackDelayMs / 3; _unack = unack; Ready(); //_timeout = Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(TimeSpan.FromMilliseconds(_timerIntervalMs), TimeSpan.FromMilliseconds(_timerIntervalMs), _self, Trigger.Instance, ActorRefs.NoSender); _timeout = Context.System.Scheduler.ScheduleTellOnceCancelable(TimeSpan.FromMilliseconds(_timerIntervalMs), Self, Trigger.Instance, ActorRefs.NoSender); }
private void Init(ConsumerConfigurationData <T> conf) { try { _log.Info($"Starting Pulsar consumer status recorder with config: {JsonSerializer.Serialize(conf, new JsonSerializerOptions{WriteIndented = true})}"); } catch (IOException e) { _log.Error($"Failed to dump config info: {e}"); } _oldTime = DateTime.Now.Millisecond; _statTimeout = _system.Scheduler.Advanced.ScheduleOnceCancelable(TimeSpan.FromSeconds(_statsIntervalSeconds), StatsAction); }
private async ValueTask <Consumer <T> > MultiTopicSubscribe <T>(ConsumerConfigurationData <T> conf, ISchema <T> schema) { Condition.CheckArgument(conf.TopicNames.Count == 0 || TopicNamesValid(conf.TopicNames), "Topics is empty or invalid."); var state = _actorSystem.ActorOf(Props.Create(() => new ConsumerStateActor()), $"StateActor{Guid.NewGuid()}"); var consumer = _actorSystem.ActorOf(Props.Create(() => new MultiTopicsConsumer <T>(state, _client, _lookup, _cnxPool, _generator, conf, _actorSystem.Scheduler.Advanced, schema, conf.ForceTopicCreation, _clientConfigurationData)), $"MultiTopicsConsumer{DateTimeHelper.CurrentUnixTimeMillis()}"); var response = await consumer.Ask <AskResponse>(new SubscribeAndCreateTopicsIfDoesNotExist(conf.TopicNames.ToList(), true)).ConfigureAwait(false); if (response.Failed) { await consumer.GracefulStop(TimeSpan.FromSeconds(5)); throw response.Exception; } _client.Tell(new AddConsumer(consumer)); return(new Consumer <T>(state, consumer, schema, conf)); }
public ConsumerStatsRecorder(ActorSystem system, ConsumerConfigurationData <T> conf, string topic, string consumerName, string subscription, long statsIntervalSeconds) { _system = system; _log = system.Log; _topic = topic; _name = consumerName; _subscription = subscription; ThroughputFormat.NumberDecimalSeparator = "0.00"; _statsIntervalSeconds = statsIntervalSeconds; _numMsgsReceived = new StripedLongAdder(); _numBytesReceived = new StripedLongAdder(); _numReceiveFailed = new StripedLongAdder(); _numBatchReceiveFailed = new StripedLongAdder(); _numAcksSent = new StripedLongAdder(); _numAcksFailed = new StripedLongAdder(); _totalMsgsReceived = new StripedLongAdder(); _totalBytesReceived = new StripedLongAdder(); _totalReceiveFailed = new StripedLongAdder(); _totalBatchReceiveFailed = new StripedLongAdder(); _totalAcksSent = new StripedLongAdder(); _totalAcksFailed = new StripedLongAdder(); Init(conf); }
public PersistentAcknowledgmentsGroupingTracker(IActorRef sequenceMap, IActorRef consumer, IActorRef generator, long consumerid, IActorRef handler, ConsumerConfigurationData <T> conf) { _handler = handler; _consumer = consumer; _generator = generator; _consumerId = consumerid; _pendingIndividualAcks = new SortedSet <MessageId>(); _acknowledgementGroupTimeMicros = conf.AcknowledgementsGroupTimeMicros; _pendingIndividualBatchIndexAcks = new SortedSet <MessageId>(); _ackReceiptEnabled = conf.AckReceiptEnabled; _batchIndexAckEnabled = conf.BatchIndexAckEnabled; _unAckedChunckedMessageIdSequenceMap = sequenceMap; BecomeActive(); _scheduledTask = _acknowledgementGroupTimeMicros > 0 ? Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(TimeSpan.FromMilliseconds(_acknowledgementGroupTimeMicros), TimeSpan.FromMilliseconds(_acknowledgementGroupTimeMicros), Self, FlushPending.Instance, ActorRefs.NoSender) : null; }
public static Props Prop(IActorRef sequenceMap, IActorRef consumer, IActorRef generator, long consumerid, IActorRef handler, ConsumerConfigurationData <T> conf) { return(Props.Create(() => new PersistentAcknowledgmentsGroupingTracker <T>(sequenceMap, consumer, generator, consumerid, handler, conf))); }
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 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 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(ConsumerConfigurationData <T> conf, IActorRef consumer, IActorRef unack) { return(Props.Create(() => new NegativeAcksTracker <T>(conf, consumer, unack))); }
private async ValueTask <Consumer <T> > SingleTopicSubscribe <T>(ConsumerConfigurationData <T> conf, ISchema <T> schema) { var schemaClone = await PreProcessSchemaBeforeSubscribe(schema, conf.SingleTopic).ConfigureAwait(false); return(await DoSingleTopicSubscribe(conf, schemaClone).ConfigureAwait(false)); }
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) { }