private void InitConsumer() { ConnectionFactory factory = new ConnectionFactory(); factory.Uri = connString; conn = factory.CreateConnection(); channel = conn.CreateModel(); channel.BasicQos(0, prefetchCount, false); buffer = new BufferQueue(); consumer = new EventingBasicConsumer(channel); channel.BasicConsume(queueName, false, consumer); // when message is recieved do following consumer.Received += (model, message) => { if (buffer.Count() > DEFAULT_ACK_COUNT) { Thread.Sleep(3000); } buffer.Enqueue(message); if (buffer.Count() == 0 || buffer.Count() == ackCount) { channel.BasicAck(message.DeliveryTag, true); } }; }
private byte[] AttemptDequeue(int?tomeout) { BasicDeliverEventArgs message; while (true) { //while buffer has no events if (buffer.Count() == 0) { Thread.Sleep(3000); } else { message = buffer.Dequeue(); break; } } try { return(message.Body); } catch (Exception e) { throw new SerializationException("Error deserializing queued message:", e); } }