Пример #1
0
 public InternalConsumer(
     IHandlerRunner handlerRunner,
     IConsumerDispatcher consumerDispatcher)
 {
     this.handlerRunner      = handlerRunner;
     this.consumerDispatcher = consumerDispatcher;
 }
Пример #2
0
    public static void PartitionsRevoked(ILogger logger,
                                         IReadOnlyList <TopicPartitionOffset> partitions,
                                         IConsumerDispatcher consumerDispatcher,
                                         Func <ConsumerContext, IEnumerable <TopicPartition>, Task> partitionsRevokedHandler,
                                         ConsumerContext context)
    {
        if (!partitions.Any())
        {
            return;
        }

        AsyncHelpers.RunSync(async() =>
        {
            var partitionsByTopic = partitions
                                    .GroupBy(p => p.Topic)
                                    .Select(g => new { Topic = g.Key, Partitions = g.Select(p => p.Partition.Value) })
                                    .ToList();

            logger.Info("Revocation: {@partitions}", partitionsByTopic);

            if (partitionsRevokedHandler != null)
            {
                await partitionsRevokedHandler(context, partitions.Select(p => p.TopicPartition));
            }

            foreach (var revocation in partitionsByTopic)
            {
                await consumerDispatcher.Revoke(revocation.Topic, revocation.Partitions);
            }
        });
    }
 public InMemConsumerImplementation(InMemEventBroker eventBroker, ILoggerFactory loggerFactory, Topics topics,
                                    IConsumerDispatcher consumerDispatcher, ConsumerContext consumerContext)
 {
     if (loggerFactory == null)
     {
         throw new ArgumentNullException(nameof(loggerFactory));
     }
     _eventBroker = eventBroker ?? throw new ArgumentNullException(nameof(eventBroker));
     _logger      = loggerFactory.GetLogger(typeof(InMemConsumerImplementation));
 }
Пример #4
0
 public BasicConsumer(Action <BasicConsumer> cancelled, IConsumerDispatcher consumerDispatcher, IQueue queue, IEventBus eventBus, IHandlerRunner handlerRunner, Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IEasyNetQLogger logger, IModel model)
 {
     Queue                   = queue;
     OnMessage               = onMessage;
     this.cancelled          = cancelled;
     this.consumerDispatcher = consumerDispatcher;
     this.eventBus           = eventBus;
     this.handlerRunner      = handlerRunner;
     this.logger             = logger;
     Model                   = model;
 }
Пример #5
0
        public BasicConsumer(Action <BasicConsumer> cancelled, IConsumerDispatcher consumerDispatcher, IQueue queue, IEventBus eventBus, IHandlerRunner handlerRunner, Func <byte[], MessageProperties, MessageReceivedInfo, Task> onMessage, IModel model)
        {
            Preconditions.CheckNotNull(onMessage, "onMessage");

            Queue                   = queue;
            OnMessage               = onMessage;
            this.cancelled          = cancelled;
            this.consumerDispatcher = consumerDispatcher;
            this.eventBus           = eventBus;
            this.handlerRunner      = handlerRunner;
            Model                   = model;
        }
Пример #6
0
        public InternalConsumer(
            IHandlerRunner handlerRunner,
            IConsumerDispatcher consumerDispatcher,
            IConventions conventions,
            IEventBus eventBus)
        {
            Preconditions.CheckNotNull(handlerRunner, "handlerRunner");
            Preconditions.CheckNotNull(consumerDispatcher, "consumerDispatcher");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(eventBus, "eventBus");

            this.handlerRunner      = handlerRunner;
            this.consumerDispatcher = consumerDispatcher;
            this.conventions        = conventions;
            this.eventBus           = eventBus;
        }
Пример #7
0
        public InternalConsumer(
            IHandlerRunner handlerRunner, 
            IEasyNetQLogger logger, 
            IConsumerDispatcher consumerDispatcher, 
            IConventions conventions, 
            IConnectionConfiguration connectionConfiguration)
        {
            Preconditions.CheckNotNull(handlerRunner, "handlerRunner");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(consumerDispatcher, "consumerDispatcher");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration");

            this.handlerRunner = handlerRunner;
            this.logger = logger;
            this.consumerDispatcher = consumerDispatcher;
            this.conventions = conventions;
            this.connectionConfiguration = connectionConfiguration;
        }
Пример #8
0
        public InternalConsumer(
            IHandlerRunner handlerRunner,
            IEasyNetQLogger logger,
            IConsumerDispatcher consumerDispatcher,
            IConventions conventions,
            IConnectionConfiguration connectionConfiguration)
        {
            Preconditions.CheckNotNull(handlerRunner, "handlerRunner");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(consumerDispatcher, "consumerDispatcher");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration");

            this.handlerRunner           = handlerRunner;
            this.logger                  = logger;
            this.consumerDispatcher      = consumerDispatcher;
            this.conventions             = conventions;
            this.connectionConfiguration = connectionConfiguration;
        }
Пример #9
0
        public BasicConsumer(
            Action <BasicConsumer> cancelled,
            IConsumerDispatcher consumerDispatcher,
            IQueue queue,
            IEventBus eventBus,
            IHandlerRunner handlerRunner,
            MessageHandler onMessage,
            IModel model
            )
        {
            Preconditions.CheckNotNull(onMessage, "onMessage");

            Queue                   = queue;
            OnMessage               = onMessage;
            this.cancelled          = cancelled;
            this.consumerDispatcher = consumerDispatcher;
            this.eventBus           = eventBus;
            this.handlerRunner      = handlerRunner;
            Model                   = model;
        }
Пример #10
0
        protected ModelBase(bool dispatchAsync, int concurrency, ISession session)
        {
            ConsumerDispatcher = dispatchAsync ?
                                 (IConsumerDispatcher) new AsyncConsumerDispatcher(this, concurrency) :
                                 new ConsumerDispatcher(this, concurrency);

            _emptyBasicProperties = CreateBasicProperties();
            Action <Exception, string> onException = (exception, context) => OnCallbackException(CallbackExceptionEventArgs.Build(exception, context));

            _basicAcksWrapper         = new EventingWrapper <BasicAckEventArgs>("OnBasicAck", onException);
            _basicNacksWrapper        = new EventingWrapper <BasicNackEventArgs>("OnBasicNack", onException);
            _basicRecoverOkWrapper    = new EventingWrapper <EventArgs>("OnBasicRecover", onException);
            _basicReturnWrapper       = new EventingWrapper <BasicReturnEventArgs>("OnBasicReturn", onException);
            _callbackExceptionWrapper = new EventingWrapper <CallbackExceptionEventArgs>(string.Empty, (exception, context) => { });
            _flowControlWrapper       = new EventingWrapper <FlowControlEventArgs>("OnFlowControl", onException);
            _modelShutdownWrapper     = new EventingWrapper <ShutdownEventArgs>("OnModelShutdown", onException);
            _recoveryWrapper          = new EventingWrapper <EventArgs>("OnModelRecovery", onException);
            session.CommandReceived   = HandleCommand;
            session.SessionShutdown  += OnSessionShutdown;
            Session = session;
        }
Пример #11
0
        protected ModelBase(ConnectionConfig config, ISession session)
        {
            ContinuationTimeout = config.ContinuationTimeout;
            ConsumerDispatcher  = config.DispatchConsumersAsync ?
                                  (IConsumerDispatcher) new AsyncConsumerDispatcher(this, config.DispatchConsumerConcurrency) :
                                  new ConsumerDispatcher(this, config.DispatchConsumerConcurrency);

            Action <Exception, string> onException = (exception, context) => OnCallbackException(CallbackExceptionEventArgs.Build(exception, context));

            _basicAcksWrapper         = new EventingWrapper <BasicAckEventArgs>("OnBasicAck", onException);
            _basicNacksWrapper        = new EventingWrapper <BasicNackEventArgs>("OnBasicNack", onException);
            _basicRecoverOkWrapper    = new EventingWrapper <EventArgs>("OnBasicRecover", onException);
            _basicReturnWrapper       = new EventingWrapper <BasicReturnEventArgs>("OnBasicReturn", onException);
            _callbackExceptionWrapper = new EventingWrapper <CallbackExceptionEventArgs>(string.Empty, (exception, context) => { });
            _flowControlWrapper       = new EventingWrapper <FlowControlEventArgs>("OnFlowControl", onException);
            _modelShutdownWrapper     = new EventingWrapper <ShutdownEventArgs>("OnModelShutdown", onException);
            _recoveryWrapper          = new EventingWrapper <EventArgs>("OnModelRecovery", onException);
            session.CommandReceived   = HandleCommand;
            session.SessionShutdown  += OnSessionShutdown;
            Session = session;
        }
Пример #12
0
 public KafkaConsumerImplementation(ILoggerFactory loggerFactory, string address, IEnumerable <string> topics, string group,
                                    IConsumerDispatcher consumerDispatcher, IPositionManager positionManager)
 {
     if (loggerFactory == null)
     {
         throw new ArgumentNullException(nameof(loggerFactory));
     }
     if (topics == null)
     {
         throw new ArgumentNullException(nameof(topics));
     }
     _logger             = loggerFactory.GetLogger(typeof(KafkaConsumerImplementation));
     _address            = address ?? throw new ArgumentNullException(nameof(address));
     _group              = group ?? throw new ArgumentNullException(nameof(group));
     _consumerDispatcher = consumerDispatcher ?? throw new ArgumentNullException(nameof(consumerDispatcher));
     _topics             = topics.ToArray();
     _positionManager    = positionManager;
     _worker             = new Thread(Run)
     {
         IsBackground = true
     };
 }
Пример #13
0
        public InternalConsumer(
            IHandlerRunner handlerRunner,
            ILogger logger,
            IConsumerDispatcher consumerDispatcher,
            IConventions conventions,
            ConnectionConfiguration connectionConfiguration,
            IEventBus eventBus)
        {
            Preconditions.CheckNotNull(handlerRunner, "handlerRunner");
            Preconditions.CheckNotNull(logger, "logger");
            Preconditions.CheckNotNull(consumerDispatcher, "consumerDispatcher");
            Preconditions.CheckNotNull(conventions, "conventions");
            Preconditions.CheckNotNull(connectionConfiguration, "connectionConfiguration");
            Preconditions.CheckNotNull(eventBus, "eventBus");

            this.handlerRunner           = handlerRunner;
            this.logger                  = logger;
            this.consumerDispatcher      = consumerDispatcher;
            this.conventions             = conventions;
            this.connectionConfiguration = connectionConfiguration;
            this.eventBus                = eventBus;
        }
Пример #14
0
        public FileSystemConsumerImplementation(string directoryPath, ILoggerFactory loggerFactory, IEnumerable <string> topics, string group, IConsumerDispatcher consumerDispatcher, IPositionManager positionManager)
        {
            if (topics == null)
            {
                throw new ArgumentNullException(nameof(topics));
            }
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }
            _directoryPath      = directoryPath;
            _consumerDispatcher = consumerDispatcher ?? throw new ArgumentNullException(nameof(consumerDispatcher));
            _positionManager    = positionManager ?? throw new ArgumentNullException(nameof(positionManager));

            _logger = loggerFactory.GetLogger(typeof(FileSystemConsumerImplementation));

            _workers = topics
                       .Select(topic => new Thread(() => PumpTopic(topic))
            {
                Name = $"Kafkaesque worker for topic '{topic}'"
            })
                       .ToList();
        }
Пример #15
0
        protected ModelBase(ISession session, ConsumerWorkService workService)
        {
            if (workService is AsyncConsumerWorkService asyncConsumerWorkService)
            {
                ConsumerDispatcher = new AsyncConsumerDispatcher(this, asyncConsumerWorkService);
            }
            else
            {
                ConsumerDispatcher = new ConcurrentConsumerDispatcher(this, workService);
            }

            _emptyBasicProperties = CreateBasicProperties();
            Action <Exception, string> onException = (exception, context) => OnCallbackException(CallbackExceptionEventArgs.Build(exception, context));

            _basicAcksWrapper         = new EventingWrapper <BasicAckEventArgs>("OnBasicAck", onException);
            _basicNacksWrapper        = new EventingWrapper <BasicNackEventArgs>("OnBasicNack", onException);
            _basicRecoverOkWrapper    = new EventingWrapper <EventArgs>("OnBasicRecover", onException);
            _basicReturnWrapper       = new EventingWrapper <BasicReturnEventArgs>("OnBasicReturn", onException);
            _callbackExceptionWrapper = new EventingWrapper <CallbackExceptionEventArgs>(string.Empty, (exception, context) => { });
            _flowControlWrapper       = new EventingWrapper <FlowControlEventArgs>("OnFlowControl", onException);
            _modelShutdownWrapper     = new EventingWrapper <ShutdownEventArgs>("OnModelShutdown", onException);
            _recoveryWrapper          = new EventingWrapper <EventArgs>("OnModelRecovery", onException);
            Initialise(session);
        }
Пример #16
0
 public ModelBase(ISession session, ConsumerWorkService workService)
 {
     Initialise(session);
     ConsumerDispatcher = new ConcurrentConsumerDispatcher(this, workService);
 }