// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.Text; using RabbitMQ.Client; using RabbitMQ.Client.Events; namespace Sub { public class MyConsumer : EventingBasicConsumer { public MyConsumer(IModel chan) : base(chan) { } public override void HandleBasicDeliver(string ctag, ulong dtag, bool redelivered, string exchange, string key, IBasicProperties props, byte[] body) { Console.WriteLine(Encoding.UTF8.GetString(body)); } } public class Program { private const string HOST = "localhost"; private const int PORT = 5672; private const string UN = "guest"; private const string PW = "guest"; private const string TNAME = "TestT"; private const string PAYLOAD = "\r\n 123\r\n ABC\r\n"; public static void Main(string[] args) { ConnectionFactory cf = new ConnectionFactory(); cf.HostName = HOST; cf.Port = PORT; cf.UserName = UN; cf.Password = PW; using(IConnection con = cf.CreateConnection()) { using(IModel chan = con.CreateModel()) { chan.ExchangeDeclare(TNAME, ExchangeType.Topic); string q = chan.QueueDeclare().QueueName; chan.QueueBind(q, TNAME, ""); chan.BasicConsume(q, true, "", true, false, null, new MyConsumer(chan)); Console.WriteLine("Press enter to exit"); Console.ReadKey(); } } } } }