public class Consumer
{
private readonly IModel c_channel;
private readonly CancellationToken c_cancellationToken;
private EventingBasicConsumer c_consumer;
public Consumer(
IConnection connection,
CancellationToken cancellationToken)
{
this.c_cancellationToken = cancellationToken;
this.c_channel = connection.CreateModel();
this.c_channel.BasicQos(0, 1, false);
this.c_channel.QueueDeclare(
queue: "hello",
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
}
public Task Start()
{
var _result = new Task(
() =>
{
this.c_consumer = new EventingBasicConsumer(this.c_channel);
this.c_channel.BasicConsume(
queue: "hello",
autoAck: true,
consumer: this.c_consumer);
this.RunConsumeLoop();
},
this.c_cancellationToken,
TaskCreationOptions.LongRunning);
_result.Start();
return _result;
}
private void RunConsumeLoop()
{
this.c_consumer.Received += (model, basicDeliverEventArgs) =>
{
try
{
//Process the message, deserialize to type, do work ..
// If we get here send ack
this.c_channel.BasicAck(basicDeliverEventArgs.DeliveryTag, false);
}
catch (Exception)
{
this.c_channel.BasicNack(basicDeliverEventArgs.DeliveryTag, false, false);
}
};
while (!this.c_cancellationToken.IsCancellationRequested)
{
Thread.Sleep(100);
}
}
} thanks Luke,
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/rabbitmq-users/5d3aca3b-6ab3-4721-91ca-0b5d8a56fc41%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
Hi Howard,
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitm...@googlegroups.com.