[rabbitmq-discuss] Acknowledging messages using the EventingBasicConsumer

Toby Riley toby.riley at rekoop.com
Thu Aug 2 12:05:30 BST 2012


I have a question I could not find a proper answer to anywhere, and it is to do with the Acknowledging messages using the  EventingBasicConsumer, I’m using   _channel.BasicAck(e.DeliveryTag, false); but there is one for o.Model. BasicAck(e.DeliveryTag, false) but the sender object (o) is null.
What is the proper way to Acknowledge message from the Received event when using the EventingBasicConsumer when you inside the delegate?
Thanks in advance
public void Subscribe(string queueName)

    var consumer = new EventingBasicConsumer();
    consumer.Received += (o, e) =>

            string data = Encoding.ASCII.GetString(e.Body);

            byte[] body = e.Body;

            body = Encoding.Convert(Encoding.GetEncoding("iso-8859-1"), Encoding.UTF8, body);
            var tempString = Encoding.UTF8.GetString(body, 0, body.Count());

            // raise my event here
            OnMessageDataReceived(new MessageDataEventArgs { MessageCallData = tempString, CallData = CallDataRecord.FromXml(tempString) });

            // ack message to remove from queue. (TODO : NOT SURE IF CORRECT BUT WORKS as the _channel is created by the consumer)
            _channel.BasicAck(e.DeliveryTag, false);
            // this does not work becuase o is null - what's the correct way of acking the message inside the delegate?
            // o.Model.BasicAck(e.DeliveryTag, false); 

    var consumerTag = _channel.BasicConsume(queueName, false, consumer);


More information about the rabbitmq-discuss mailing list