Last active
December 17, 2024 10:07
-
-
Save kjnilsson/732c0883c7807647e84ba5be2c3027f5 to your computer and use it in GitHub Desktop.
RabbitMQ .NET client async consumer example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using RabbitMQ.Client; | |
using RabbitMQ.Client.Events; | |
namespace ConsoleApplication | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
var cf = new ConnectionFactory{ DispatchConsumersAsync = true }; | |
using(var conn = cf.CreateConnection()) | |
using(var model = conn.CreateModel()) | |
{ | |
model.QueueDeclare("test"); | |
var consumer = new AsyncEventingBasicConsumer(model); | |
var tag = model.BasicConsume("test", true, consumer); | |
consumer.Received += async (o, a) => | |
{ | |
Console.WriteLine("Delivery: " + a.DeliveryTag); | |
await Task.Yield(); | |
}; | |
Console.ReadLine(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment