public AzureBusQueuePublisher(AzureQueueMqSettings settings, Action <string> logMessage, Action <string> logError)
        {
            _settings   = settings;
            _logMessage = logMessage;
            _logError   = logError;
            _factory    = MessagingFactory.CreateFromConnectionString(settings.ConnectionString);

            _namespaceManager =
                NamespaceManager.CreateFromConnectionString(settings.ConnectionString);
        }
            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)));
                }
            }
예제 #3
0
            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
                });
            }