public QueueDeclareOk QueueDeclare(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary <string, object> arguments) { if (string.IsNullOrWhiteSpace(queue)) { var bytes = new byte[16]; Random.NextBytes(bytes); var firstPart = Convert.ToBase64String(bytes).Substring(0, 11); Random.NextBytes(bytes); var secondPart = Convert.ToBase64String(bytes).Substring(0, 10); queue = $"amq.gen-{firstPart}-{secondPart}"; } var queueInstance = new Queue { Name = queue, IsDurable = durable, IsExclusive = exclusive, IsAutoDelete = autoDelete, Arguments = arguments as IDictionary }; Func <string, Queue, Queue> updateFunction = (name, existing) => existing; _server.Queues.AddOrUpdate(queue, queueInstance, updateFunction); return(new QueueDeclareOk(queue, 0, 0)); }
public QueueDeclareOk QueueDeclare(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary <string, object> arguments) { var queueInstance = new Queue { Name = queue, IsDurable = durable, IsExclusive = exclusive, IsAutoDelete = autoDelete, Arguments = arguments as IDictionary }; Func <string, Queue, Queue> updateFunction = (name, existing) => existing; _server.Queues.AddOrUpdate(queue, queueInstance, updateFunction); return(new QueueDeclareOk(queue, 0, 0)); }
public QueueDeclareOk QueueDeclare(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary <string, object> arguments) { var queueInstance = new Queue { Name = queue, IsDurable = durable, IsExclusive = exclusive, IsAutoDelete = autoDelete, Arguments = arguments }; if (exclusive && _server.Queues.ContainsKey(queue) && !_localQueues.ContainsKey(queue)) { throw new OperationInterruptedException(new ShutdownEventArgs(ShutdownInitiator.Peer, 405, $"RESOURCE_LOCKED - cannot obtain exclusive access to locked queue '{queue}' in vhost '/'. It could be originally declared on another connection or the exclusive property value does not match that of the original declaration.")); } Func <string, Queue, Queue> updateFunction = (name, existing) => existing; _server.Queues.AddOrUpdate(queue, queueInstance, updateFunction); _localQueues.AddOrUpdate(queue, queueInstance, updateFunction); return(new QueueDeclareOk(queue, 0, 0)); }
private void NotifyConsumerOfExistingMessages(string consumerTag, IBasicConsumer consumer, Queue queueInstance) { foreach (var message in queueInstance.Messages) { NotifyConsumerOfMessage(consumerTag, consumer, message); } }
private void NotifyConsumerWhenMessagesAreReceived(string consumerTag, IBasicConsumer consumer, Queue queueInstance) { queueInstance.MessagePublished += (sender, message) => { NotifyConsumerOfMessage(consumerTag, consumer, message); }; }
private void NotifyConsumerOfExistingMessages(string consumerTag, IBasicConsumer consumer, Queue queueInstance) { while (queueInstance.Messages.Any()) { if (queueInstance.Messages.TryDequeue(out var message)) { NotifyConsumerOfMessage(consumerTag, consumer, message); } } }