public void CreateExchange() { WithChannel.Do(channel => channel.ExchangeDeclare( exchange: subscription, type: ExchangeType.Direct, durable: true)); }
public void Spike() { WithChannel.Do(model => { var queue = model.QueueDeclare("confirms.test", false, false, false, null); model.ConfirmSelect(); model.BasicAcks += (model1, args) => Console.Out.WriteLine("Delivered DeliveryTag: '{0}', Multiple: {1}", args.DeliveryTag, args.Multiple); model.BasicNacks += (model1, args) => Console.Out.WriteLine("Failed DeliverTag: '{0}', Multiple: {1}", args.DeliveryTag, args.Multiple); Publish(model, queue, "Hello 1"); Publish(model, queue, "Hello 2"); Console.Out.WriteLine("Waiting for result"); Thread.Sleep(2000); BasicGetResult result; do { Thread.Sleep(100); result = model.BasicGet(queue, false); } while (result == null); Console.Out.WriteLine("result.Body = {0}", Encoding.UTF8.GetString(result.Body)); model.BasicAck(result.DeliveryTag, false); }); }
public void SetUp() { WithChannel.Do(channel => { channel.QueueDeclare(high, true, false, false, null); channel.QueueDeclare(low, true, false, false, null); }); }
public void CreateQueue() { WithChannel.Do(channel => { var returnedName = channel.QueueDeclare(queueName, false, false, false, null); Console.WriteLine("Declared queue: {0}", returnedName); }); }
public void Publish(string queue) { WithChannel.Do(channel => { for (var i = 0; i < publishCount; i++) { channel.BasicPublish("", queue, channel.CreateBasicProperties(), GetMessage()); } }); }
public void InitializeQueue() { WithChannel.Do(channel => channel.QueueDeclare( ackNackQueue, durable: true, exclusive: false, autoDelete: false, arguments: null)); }
public void PublishSequence() { WithChannel.Do(channel => { for (int i = 0; i < 10; i++) { var properties = channel.CreateBasicProperties(); var body = Encoding.UTF8.GetBytes(i.ToString()); channel.BasicPublish("", ackNackQueue, properties, body); } }); }
public void GetMessagesFor(string subscriber) { WithChannel.Do(channel => { var consumer = new CallbackConsumer(); channel.BasicConsume(subscriber, true, consumer); // give the consumer some time to get messages Thread.Sleep(1000); }); Console.WriteLine("Stopped consuming messages"); }
public void PublishMessage() { WithChannel.Do(channel => { var defaultProperties = channel.CreateBasicProperties(); var messageText = "Hello World " + Guid.NewGuid().ToString().Substring(0, 5); var message = Encoding.UTF8.GetBytes(messageText); channel.BasicPublish(subscription, subscription, defaultProperties, message); Console.WriteLine("Published Message '{0}'", messageText); }); }
public void SubscribeWithSubscriber() { WithChannel.Do(channel => { var subscription = new Subscription(channel, ackNackQueue); foreach (BasicDeliverEventArgs deliverEventArgs in subscription) { var message = Encoding.UTF8.GetString(deliverEventArgs.Body); Console.Out.WriteLine("message = {0}", message); subscription.Ack(deliverEventArgs); } }); }
public void Subscribe(string subscriberName) { WithChannel.Do(channel => { var queue = channel.QueueDeclare(subscriberName, durable: true, exclusive: false, autoDelete: false, arguments: null); channel.QueueBind(queue, subscription, subscription); Console.WriteLine("{0}: {1}", subscriberName, queue); }); }
public void SubscribeAck() { const int prefetchCount = 1; const bool noAck = false; const int numberOfMessagesToConsume = 1; WithChannel.Do(channel => { channel.BasicQos(0, prefetchCount, false); var consumer = new LocalQueueingBasicConsumer(channel); channel.BasicConsume(ackNackQueue, noAck, consumer); var running = true; var thread = new Thread(_ => { var count = 0; while (running && count++ < numberOfMessagesToConsume) { try { var basicDeliverEventArgs = (BasicDeliverEventArgs)consumer.Queue.Dequeue(); if (basicDeliverEventArgs != null) { var message = Encoding.UTF8.GetString(basicDeliverEventArgs.Body); Console.Out.WriteLine("message = {0}", message); Console.WriteLine("Redelivered: {0}", basicDeliverEventArgs.Redelivered); consumer.Model.BasicAck(basicDeliverEventArgs.DeliveryTag, false); // consumer.Model.BasicNack(basicDeliverEventArgs.DeliveryTag, false, requeue:true); } } catch (EndOfStreamException) { break; } } }); thread.Start(); Thread.Sleep(1000); running = false; channel.Close(); consumer.Queue.Close(); }); }
private static void Publish(string routingKey) { WithChannel.Do(channel => { channel.ExchangeDeclare( exchange: exchange, type: ExchangeType.Topic, durable: true); var defaultProperties = channel.CreateBasicProperties(); var messageText = "Hello World " + Guid.NewGuid().ToString().Substring(0, 5); var message = Encoding.UTF8.GetBytes(messageText); channel.BasicPublish(exchange, routingKey, defaultProperties, message); Console.WriteLine("Published Message '{0}'", messageText); }); }
public void BasicGet() { WithChannel.Do(channel => { var result = channel.BasicGet(queueName, true); if (result == null) { Console.WriteLine("Queue is empty"); } else { var messageText = Encoding.UTF8.GetString(result.Body); Console.WriteLine("Got message: {0}", messageText); } }); }
private static void TopicSubscribe(string routingKey, string queueName) { WithChannel.Do(channel => { var queue = channel.QueueDeclare(queueName, durable: true, exclusive: false, autoDelete: false, arguments: null); channel.QueueBind(queue, exchange, routingKey); Console.WriteLine("{0}: {1}", queueName, queue); var consumer = new CallbackConsumer(); channel.BasicConsume(queue, true, consumer); // give the consumer some time to get messages Thread.Sleep(1000); Console.WriteLine("Stopped consuming"); }); }