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); }
public ReaderConfigBuilder <T> EventListener(IConsumerEventListener consumerEventListener) { _conf.EventListener = consumerEventListener; return(this); }