public Task <string> BasicConsume(ConsumeMode mode, Func <MessageDelivery, Task> consumer, string queue, string consumerTag, bool withoutAcks, bool exclusive, IDictionary <string, object> arguments, bool waitConfirmation) { if (consumer == null) { throw new ArgumentNullException("consumer"); } if (!waitConfirmation && string.IsNullOrEmpty(consumerTag)) { throw new ArgumentException("You must specify a consumer tag if waitConfirmation = false"); } if (!string.IsNullOrEmpty(consumerTag)) { _consumerSubscriptions[consumerTag] = new BasicConsumerSubscriptionInfo { Mode = mode, Callback = consumer }; } return(_io.__BasicConsume(mode, queue, consumerTag, withoutAcks, exclusive, arguments, waitConfirmation, consumerTag2 => { _consumerSubscriptions[consumerTag2] = new BasicConsumerSubscriptionInfo { Mode = mode, Callback = consumer }; })); }
private void RegisterConsumer(string consumerTag, BasicConsumerSubscriptionInfo info) { var added = _consumerSubscriptions.TryAdd(consumerTag, info); if (!added) { throw new Exception("Consumer already exists for tag " + consumerTag); } }
private void SerializedDelivery(BasicConsumerSubscriptionInfo consumer) { while (!consumer._cancelThread && !this.IsClosed) { consumer._messageAvailableEv.WaitOne(); MessageDelivery delivery; while (consumer._receivedMessages.TryDequeue(out delivery)) { try { if (consumer.Callback != null) { consumer.Callback(delivery).ConfigureAwait(false).GetAwaiter().GetResult(); continue; } consumer._consumer.Consume(delivery).ConfigureAwait(false).GetAwaiter().GetResult(); } catch (Exception ex) { if (LogAdapter.IsErrorEnabled) { LogAdapter.LogError(LogSource, "Consumer error. Tag " + consumer.ConsumerTag, ex); } } finally { if (!delivery.TakenOver) { delivery.Dispose(); } } } } if (LogAdapter.ExtendedLogEnabled) { LogAdapter.LogDebug(LogSource, "Consumer exiting. Tag " + consumer.ConsumerTag); } }
private void SerializedDelivery(BasicConsumerSubscriptionInfo consumer) { while (!consumer._cancelThread && !this.IsClosed) { consumer._messageAvailableEv.WaitOne(); MessageDelivery delivery; while (consumer._receivedMessages.TryDequeue(out delivery)) { try { if (consumer.Callback != null) { consumer.Callback(delivery).Wait(); continue; } consumer._consumer.Consume(delivery).Wait(); } catch (Exception ex) { LogAdapter.LogError("Channel", "Consumer error. Tag " + consumer.ConsumerTag, ex); } finally { this.Return(delivery.properties); if (delivery.bodySize != 0) { delivery.stream.Dispose(); } } } } if (LogAdapter.ExtendedLogEnabled) { LogAdapter.LogDebug("Channel", "Consumer exiting. Tag " + consumer.ConsumerTag); } }