Beispiel #1
0
        public void ReadQueue <T>(string queueName, Action <T> callback)
        {
            while (Chanel.BasicGet(queueName, false) is BasicGetResult response && response != null)
            {
                T message = RabbitMQExtended.DeserializeResponse <T>(response.Body);

                callback(message);

                Chanel.BasicAck(response.DeliveryTag, false);
            }
        }
Beispiel #2
0
        public void KeepListening <T>(string queueName, Action <T> callback)
        {
            var consumer = new EventingBasicConsumer(Chanel);

            //Get one message at time. That's good for more than one consumer per queue.
            Chanel.BasicQos(0, 1, false);

            consumer.Received += (model, ea) =>
            {
                T message = RabbitMQExtended.DeserializeResponse <T>(ea.Body);
                callback(message);
                Chanel.BasicAck(ea.DeliveryTag, false);
            };

            Chanel.BasicConsume(queue: queueName,
                                autoAck: false,
                                consumer: consumer);
        }