internal Binding( MessagingFactory messagingFactory, NamespaceManager namespaceManager, AzureQueueMqSettings settings, string queueName, Action <string> logMessage, Action <string> logError) { _messagingFactory = messagingFactory; _logMessage = logMessage; _logError = logError; _queueName = queueName; _excludeQueuesFromLogging = new LoggingConfiguration().ExcludeQueuesFromLogging(); if (!namespaceManager.QueueExists(queueName)) { var queueDescription = new QueueDescription(_queueName); namespaceManager.CreateQueue(settings.QueueBuilderConfig(queueDescription, typeof(T))); } }
internal Binding(MessagingFactory messagingFactory, NamespaceManager namespaceManager, AzureQueueMqSettings settings, Action <string> logMessage, Action <string> logError) { var queueName = settings.QueueNameBuilderForSubscriber(typeof(T)); _receiver = messagingFactory.CreateMessageReceiver(queueName, ReceiveMode.PeekLock); _excludeQueuesFromLogging = new LoggingConfiguration().ExcludeQueuesFromLogging(); if (!namespaceManager.QueueExists(queueName)) { var queueDescription = new QueueDescription(queueName); namespaceManager.CreateQueue(settings.QueueBuilderConfig(queueDescription, typeof(T))); } _receiver.OnMessage(message => { try { var bodyStream = message.GetBody <Stream>(); using (var reader = new StreamReader(bodyStream)) { var body = reader.ReadToEnd(); if (!_excludeQueuesFromLogging.Contains(queueName)) { logMessage($"Received '{queueName}': {body}"); } Subject.OnNext(JObject.Parse(body)["data"].ToObject <T>()); } } catch (Exception ex) { logError($"Message {queueName}': {message} -> consumer error: {ex}"); } }, new OnMessageOptions { AutoComplete = true }); }