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); }
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); } }
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)); })); }
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); }