Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace rabbitMQTest
class Program
static void Main(string[] args)
ConnectionFactory factory = new ConnectionFactory()
HostName = "<host>",
UserName = "<username>",
Password = "<password>",
VirtualHost = "/"
IModel channel;
IConnection connection;
EventingBasicConsumer consumer;
factory.AutomaticRecoveryEnabled = true;
factory.NetworkRecoveryInterval = TimeSpan.FromSeconds(5);
factory.RequestedHeartbeat = 5;
factory.SocketReadTimeout = 5000;
factory.SocketWriteTimeout = 5000;
factory.ContinuationTimeout = TimeSpan.FromSeconds(5);
connection = factory.CreateConnection();
channel = connection.CreateModel();
string q = channel.QueueDeclare().QueueName;
channel.QueueBind(q, "amq.rabbitmq.event", "queue.*");
consumer = new EventingBasicConsumer(channel);
consumer.Received += Consumer;
channel.BasicConsume(queue: q, autoAck: true, consumer: consumer);
private static void Consumer(object sender, BasicDeliverEventArgs e)
e.BasicProperties.Headers.TryGetValue("vhost", out object vhost);
Dictionary<string, string> headers = e.BasicProperties.Headers.ToDictionary(key => key.Key, value => Encoding.UTF8.GetString((byte[])value.Value));
//throw new NotImplementedException();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.