Exemplo n.º 1
0
 public IQueueConsumer GetConsumer <T>(string queueName, IConsumerCountManager consumerCountManager,
                                       IMessageProcessingWorker <T> messageProcessingWorker, IMessageRejectionHandler messageRejectionHandler)
     where T : class
 {
     return(new RabbitMQConsumer <T>(
                connectionPool: _connectionPool,
                queueName: queueName,
                serializer: _serializer,
                errorLogger: _errorLogger,
                messageProcessingWorker: messageProcessingWorker,
                consumerCountManager: consumerCountManager,
                messageRejectionHandler: messageRejectionHandler));
 }
 public RabbitMQConsumerWorker(IConnection connection, string queueName,
                               IMessageProcessingWorker <T> messageProcessingWorker, IMessageRejectionHandler messageRejectionHandler,
                               ISerializer serializer, Func <bool> scaleCallbackFunc)
 {
     _model = connection.CreateModel();
     _model.BasicQos(0, 1, false);
     _subscription            = new Subscription(_model, queueName, false);
     _messageProcessingWorker = messageProcessingWorker;
     _messageRejectionHandler = messageRejectionHandler;
     _serializer         = serializer;
     _scaleCallbackFunc  = scaleCallbackFunc;
     CheckAliveFrequency = new TimeSpan(0, 0, 10);
 }
        public RabbitMQConsumer(RabbitMQConnectionPool connectionPool, string queueName,
                                IMessageProcessingWorker <T> messageProcessingWorker, ISerializer serializer = null, IErrorLogger errorLogger = null,
                                IConsumerCountManager consumerCountManager = null, IMessageRejectionHandler messageRejectionHandler           = null)
        {
            _connectionPool          = connectionPool;
            _queueName               = queueName;
            _serializer              = serializer ?? new JsonSerializer();
            _errorLogger             = errorLogger;
            _messageProcessingWorker = messageProcessingWorker;
            _consumerCountManager    = consumerCountManager ?? new ConsumerCountManager();
            _messageRejectionHandler = messageRejectionHandler ?? new MessageDeserializationRejectionHandler(connectionPool);

            _consumerWorkersCount    = 0;
            _cancellationTokenSource = new CancellationTokenSource();
        }
 public RabbitMQConsumerWorker(ILogger logger, IQueueClient queueClient, IModel modelConsumer, IModel modelPublisher, string queueName,
                               IMessageProcessingWorker <T> messageProcessingWorker, IMessageRejectionHandler messageRejectionHandler,
                               ISerializer serializer, ushort prefetchCount = 1)
 {
     _logger                  = logger;
     _queueClient             = queueClient;
     _modelConsumer           = modelConsumer;
     _modelPublisher          = modelPublisher;
     _queueName               = queueName;
     _prefetchCount           = prefetchCount;
     _messageProcessingWorker = messageProcessingWorker;
     _messageRejectionHandler = messageRejectionHandler;
     _serializer              = serializer;
     CheckAliveFrequency      = new TimeSpan(0, 0, 10);
     SubscribeModelEvents();
 }
        public RabbitMQConsumerWorker(IConnection connection, string queueName, IMessageProcessingWorker messageProcessingWorker, IMessageRejectionHandler messageRejectionHandler, Func <int> scaleCallbackFunc, Type expectedType, CancellationToken parentToken)
        {
            Contract.Requires(connection != null, "connection is required");
            Contract.Requires(string.IsNullOrWhiteSpace(queueName) == false, "queueName is required");
            Contract.Requires(messageProcessingWorker != null, "messageProcessingWorker is required");
            Contract.Requires(scaleCallbackFunc != null, "scaleCallbackFunc is required");

            this._model = connection.CreateModel();
            this._model.BasicQos(0, 1, false);
            this._subscription            = new Subscription(this._model, queueName, false);
            this._messageProcessingWorker = messageProcessingWorker;
            this._messageRejectionHandler = messageRejectionHandler;
            this._cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(parentToken);
            this._scaleCallbackFunc       = scaleCallbackFunc;
            this._expectedType            = expectedType;
            this.CheckAliveFrequency      = new TimeSpan(0, 0, 10);
        }
Exemplo n.º 6
0
 public RabbitMQConsumer(
     ILogger logger,
     IQueueClient queueClient,
     ConnectionFactory connectionFactory,
     RabbitMQConnection connectionConsumer,
     RabbitMQConnection connectionPublisher,
     string queueName,
     IMessageProcessingWorker <T> messageProcessingWorker,
     ISerializer serializer = null,
     IConsumerCountManager consumerCountManager       = null,
     IMessageRejectionHandler messageRejectionHandler = null,
     ushort prefetchCount = 1)
     : base(connectionFactory, connectionConsumer, connectionPublisher, queueName, serializer, logger, consumerCountManager, messageRejectionHandler, prefetchCount)
 {
     _queueClient             = queueClient;
     _logger                  = logger;
     _messageProcessingWorker = messageProcessingWorker;
 }
        public IQueueConsumer CreateConsumer <T>(string queueName, IConsumerCountManager consumerCountManager,
                                                 IMessageProcessingWorker <T> messageProcessingWorker, IMessageRejectionHandler messageRejectionHandler,
                                                 ushort prefetchCount = 1)
            where T : class
        {
            RabbitMQConnection connectionConsumer = ConnectionPerQueue
                ? _rabbitMQConnectionManager.CreateConnection($"consumer: {queueName}")
                : _rabbitMQConnectionManager.ConnectionByName("consumer") ?? _rabbitMQConnectionManager.CreateConnection("consumer");

            var connectionPublisher = _rabbitMQConnectionManager.ConnectionByName("publisher");

            return(new RabbitMQConsumer <T>(
                       queueClient: this,
                       connectionConsumer: connectionConsumer,
                       connectionPublisher: connectionPublisher,
                       connectionFactory: _connectionFactory,
                       queueName: queueName,
                       serializer: _serializer,
                       logger: _logger,
                       messageProcessingWorker: messageProcessingWorker,
                       consumerCountManager: consumerCountManager,
                       messageRejectionHandler: messageRejectionHandler,
                       prefetchCount: prefetchCount));
        }
    public RabbitMQConsumerWorker(IConnection connection, string queueName, IMessageProcessingWorker messageProcessingWorker, IMessageRejectionHandler messageRejectionHandler, Func <int> scaleCallbackFunc, Type expectedType, CancellationToken parentToken)
    {
        Contract.Requires(connection != null, "connection is required");
        Contract.Requires(string.IsNullOrWhiteSpace(queueName) == false, "queueName is required");
        Contract.Requires(messageProcessingWorker != null, "messageProcessingWorker is required");
        Contract.Requires(scaleCallbackFunc != null, "scaleCallbackFunc is required");

        this.queueName = queueName;
        this.model     = connection.CreateModel();
        this.model.BasicQos(0, 1, false);
        this.consumer = new EventingBasicConsumer(this.model);
        this.messageProcessingWorker = messageProcessingWorker;
        this.messageRejectionHandler = messageRejectionHandler;
        this.cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(parentToken);
        this.scaleCallbackFunc       = scaleCallbackFunc;
        this.expectedType            = expectedType;
        this.CheckAliveFrequency     = new TimeSpan(0, 0, 10);


        this.consumer.Received     += this.OnMessage;
        this.consumer.Registered   += this.Consumer_Registered;
        this.consumer.Shutdown     += this.Consumer_Shutdown;
        this.consumer.Unregistered += this.Consumer_Unregistered;
    }
Exemplo n.º 9
0
 public IQueueConsumer GetConsumer(string queueName, IConsumerCountManager consumerCountManager, IMessageProcessingWorker messageProcessingWorker, Type expectedType, IMessageRejectionHandler messageRejectionHandler)
 {
     return(new RabbitMQConsumer(
                connectionPool: this.ConnectionPool,
                queueName: queueName,
                expectedType: expectedType,
                messageProcessingWorker: messageProcessingWorker,
                consumerCountManager: consumerCountManager,
                messageRejectionHandler: messageRejectionHandler));
 }
Exemplo n.º 10
0
        public RabbitMQConsumer(RabbitMQConnectionPool connectionPool, string queueName, Type expectedType, IMessageProcessingWorker messageProcessingWorker, ConsumerCountManager consumerCountManager, IMessageRejectionHandler messageRejectionHandler)
        {
            //Set using constructor parameters
            this.ConnectionPool          = connectionPool;
            this.QueueName               = queueName;
            this.ExpectedType            = expectedType;
            this.MessageProcessingWorker = messageProcessingWorker;
            this._consumerCountManager   = consumerCountManager;
            this.MessageRejectionHandler = messageRejectionHandler;

            //Set using default values
            this._consumerWorkersCount    = 0;
            this._cancellationTokenSource = new CancellationTokenSource();
            this._isStopped = true;
        }