Exemple #1
0
        public void Consume(IRabbitMessageHandler messageHandler)
        {
            if (_rabbitConfiguration == null)
            {
                throw new ApplicationException("Rabbit configuration is missing.");
            }

            if (messageHandler == null)
            {
                throw new ArgumentNullException(nameof(messageHandler));
            }

            _consumer           = new EventingBasicConsumer(_channel);
            _consumer.Received += (model, result) =>
            {
                try
                {
                    _channel.BasicAck(result.DeliveryTag, false);
                    messageHandler.Handle(model, result);
                }
                catch (Exception ex)
                {
                    //Log exception
                }
            };

            _channel.BasicConsume(_rabbitConfiguration.Queue, false, _consumer);
        }
Exemple #2
0
 public static IDisposable SubscribeOnQueueToMessage <T>(this IObservableConnection connection, ISubscriptionConfig config, IRabbitMessageHandler <T> handler)
 {
     return(connection.Queue(config.QueueName)
            .Open()
            .Stream <T>()
            .SubscribeWithAck(rm => { handler.Handle(rm.Message); }));
 }
        public void Get(MessagingConfiguration messagingConfiguration, IRabbitMessageHandler messageHandler)
        {
            SetupChannel(messagingConfiguration);

            var result = _channel.BasicGet(messagingConfiguration.QueueName, true);

            while (result != null)
            {
                messageHandler.Handle(result);
                result = _channel.BasicGet(messagingConfiguration.QueueName, true);
            }
        }
Exemple #4
0
 public static IDisposable SubscribeOnQueueToMessage <T>(this IObservableConnection connection, IBatchSubscriptionConfig config, IRabbitMessageHandler <IEnumerable <T> > handler)
 {
     return(SubscribeWithAck(connection.Queue(config.QueueName)
                             .Open()
                             .Stream <T>()
                             .Buffer(config.BufferTimeout, config.BufferSize)
                             .Where(m => m.Any())
                             .Select(l => l.AsEnumerable()), l =>
     {
         var rabbitMessages = l.ToArray();
         handler.Handle(rabbitMessages.Select(m => m.Message));
     }));
 }
Exemple #5
0
        public void Get(IRabbitMessageHandler messageHandler)
        {
            if (_rabbitConfiguration == null)
            {
                throw new ApplicationException("Rabbit configuration is missing.");
            }

            var result = _channel.BasicGet(_rabbitConfiguration.Queue, true);

            while (result != null)
            {
                messageHandler.Handle(result);
                result = _channel.BasicGet(_rabbitConfiguration.Queue, true);
            }
        }
        public void Consume(MessagingConfiguration messagingConfiguration, IRabbitMessageHandler messageHandler)
        {
            SetupChannel(messagingConfiguration);

            _consumer           = new EventingBasicConsumer(_channel);
            _consumer.Received += (model, result) =>
            {
                try
                {
                    _channel.BasicAck(result.DeliveryTag, false);
                    messageHandler.Handle(model, result);
                }
                catch (Exception ex)
                {
                    //Log exception
                }
            };

            _consumerTag = _channel.BasicConsume(messagingConfiguration.QueueName, false, _consumer);
        }