public TopicSubscriptionConsumer(ServiceBusMessageBus messageBus, AbstractConsumerSettings consumerSettings, IMessageProcessor <Message> messageProcessor)
     : base(messageBus, consumerSettings,
            messageBus.ProviderSettings.SubscriptionClientFactory(new SubscriptionFactoryParams(consumerSettings.Topic, consumerSettings.GetSubscriptionName())),
            messageProcessor,
            messageBus.LoggerFactory.CreateLogger <TopicSubscriptionConsumer>())
 {
     _subscriptionClient = (SubscriptionClient)Client;
 }
Ejemplo n.º 2
0
 public QueueConsumer(ServiceBusMessageBus messageBus, AbstractConsumerSettings consumerSettings, IMessageProcessor <Message> messageProcessor)
     : base(messageBus, consumerSettings,
            messageBus.ServiceBusSettings.QueueClientFactory(consumerSettings.Topic),
            messageProcessor,
            LogManager.GetLogger <QueueConsumer>())
 {
     _queueClient = (IQueueClient)Client;
 }
 internal static string GetSubscriptionName(this AbstractConsumerSettings consumerSettings, bool required = true)
 {
     if (!consumerSettings.Properties.ContainsKey(SubscriptionNameKey) && !required)
     {
         return(null);
     }
     return(consumerSettings.Properties[SubscriptionNameKey] as string);
 }
Ejemplo n.º 4
0
        protected void AddConsumer(AbstractConsumerSettings consumerSettings, IMessageProcessor <Message> messageProcessor)
        {
            var consumer = consumerSettings.GetKind() == PathKind.Topic
                ? new TopicSubscriptionConsumer(this, consumerSettings, messageProcessor) as BaseConsumer
                : new QueueConsumer(this, consumerSettings, messageProcessor);

            _consumers.Add(consumer);
        }
        public static void SetGroup(this AbstractConsumerSettings consumerSettings, string group)
        {
            if (consumerSettings == null)
            {
                throw new ArgumentNullException(nameof(consumerSettings));
            }

            consumerSettings.Properties[GroupKey] = group;
        }
Ejemplo n.º 6
0
 public QueueConsumer(ServiceBusMessageBus messageBus, AbstractConsumerSettings consumerSettings, IMessageProcessor <Message> messageProcessor)
     : base(messageBus ?? throw new ArgumentNullException(nameof(messageBus)),
            consumerSettings ?? throw new ArgumentNullException(nameof(consumerSettings)),
            messageBus.ProviderSettings.QueueClientFactory(consumerSettings.Topic),
            messageProcessor,
            LogManager.GetLogger <QueueConsumer>())
 {
     _queueClient = (IQueueClient)Client;
 }
        internal static void SetSubscriptionName(this AbstractConsumerSettings consumerSettings, string subscriptionName)
        {
            if (subscriptionName is null)
            {
                throw new ArgumentNullException(nameof(subscriptionName));
            }

            consumerSettings.Properties[SubscriptionNameKey] = subscriptionName;
        }
Ejemplo n.º 8
0
        public static string FormatIf(this AbstractConsumerSettings settings, bool logLevel)
        {
            if (!logLevel)
            {
                return(string.Empty);
            }

            return($"Topic: {settings.Topic}");
        }
Ejemplo n.º 9
0
        private static void AssertIsTopicForSubscriptionName(AbstractConsumerSettings settings)
        {
            if (settings.GetKind() == PathKind.Queue)
            {
                var methodName = $".{nameof(SubscriptionName)}(...)";

                var messageType = settings is ConsumerSettings consumerSettings
                    ? consumerSettings.MessageType.FullName
                    : string.Empty;
                throw new ConfigurationMessageBusException($"The subscription name configuration ({methodName}) does not apply to Azure ServiceBus queues (it only applies to topic consumers). Remove the {methodName} configuration for type {messageType} and queue {settings.Topic} or change the consumer configuration to consume from topic {settings.Topic} instead.");
            }
        }
        public static string GetGroup(this AbstractConsumerSettings consumerSettings)
        {
            if (consumerSettings == null)
            {
                throw new ArgumentNullException(nameof(consumerSettings));
            }

            if (!consumerSettings.Properties.TryGetValue(GroupKey, out var group))
            {
                return(null);
            }
            return(group as string);
        }
Ejemplo n.º 11
0
        protected void AddConsumer(AbstractConsumerSettings consumerSettings, IMessageProcessor <Message> messageProcessor)
        {
            if (consumerSettings is null)
            {
                throw new ArgumentNullException(nameof(consumerSettings));
            }

            var consumer = consumerSettings.GetKind() == PathKind.Topic
                ? new TopicSubscriptionConsumer(this, consumerSettings, messageProcessor) as BaseConsumer
                : new QueueConsumer(this, consumerSettings, messageProcessor);

            _consumers.Add(consumer);
        }
Ejemplo n.º 12
0
        public static string FormatIf(this AbstractConsumerSettings settings, bool logLevel)
        {
            if (!logLevel)
            {
                return(string.Empty);
            }

            if (settings.GetKind() == PathKind.Queue)
            {
                return($"Queue: {settings.Topic}");
            }
            return($"Topic: {settings.Topic}, SubscriptionName: {settings.GetSubscriptionName()}");
        }
Ejemplo n.º 13
0
        public static string FormatIf(this AbstractConsumerSettings consumerSettings, Message msg, bool logLevel)
        {
            if (!logLevel)
            {
                return(string.Empty);
            }

            if (consumerSettings.GetKind() == PathKind.Queue)
            {
                return($"Queue: {consumerSettings.Topic}, SequenceNumber: {msg.SystemProperties.SequenceNumber}, DeliveryCount: {msg.SystemProperties.DeliveryCount}");
            }

            return($"Topic: {consumerSettings.Topic}, SubscriptionName: {consumerSettings.GetSubscriptionName()}, SequenceNumber: {msg.SystemProperties.SequenceNumber}, DeliveryCount: {msg.SystemProperties.DeliveryCount}");
        }
Ejemplo n.º 14
0
        public BaseConsumer(ServiceBusMessageBus messageBus, AbstractConsumerSettings consumerSettings, IReceiverClient client, IMessageProcessor <Message> messageProcessor, ILog log)
        {
            _log             = log;
            MessageBus       = messageBus ?? throw new ArgumentNullException(nameof(messageBus));
            ConsumerSettings = consumerSettings ?? throw new ArgumentNullException(nameof(consumerSettings));
            Client           = client ?? throw new ArgumentNullException(nameof(client));

            MessageProcessor = messageProcessor ?? throw new ArgumentNullException(nameof(messageProcessor));

            // Configure the message handler options in terms of exception handling, number of concurrent messages to deliver, etc.
            var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler)
            {
                // Maximum number of concurrent calls to the callback ProcessMessagesAsync(), set to 1 for simplicity.
                // Set it according to how many messages the application wants to process in parallel.
                MaxConcurrentCalls = consumerSettings.Instances,

                // Indicates whether the message pump should automatically complete the messages after returning from user callback.
                // False below indicates the complete operation is handled by the user callback as in ProcessMessagesAsync().
                AutoComplete = false
            };

            // Register the function that processes messages.
            Client.RegisterMessageHandler(ProcessMessagesAsync, messageHandlerOptions);
        }
Ejemplo n.º 15
0
        protected void AddConsumer(AbstractConsumerSettings consumerSettings, ISubscriber subscriber, IMessageProcessor <byte[]> messageProcessor)
        {
            var consumer = new RedisChannelConsumer(consumerSettings, subscriber, messageProcessor);

            _consumers.Add(consumer);
        }
Ejemplo n.º 16
0
 public static void SetGroup(this AbstractConsumerSettings consumerSettings, string group)
 {
     consumerSettings.Properties[GroupKey] = group;
 }
Ejemplo n.º 17
0
 public static string GetGroup(this AbstractConsumerSettings consumerSettings)
 {
     return(consumerSettings.Properties[GroupKey] as string);
 }
Ejemplo n.º 18
0
 internal static string GetSubscriptionName(this AbstractConsumerSettings consumerSettings)
 {
     return(consumerSettings.Properties[SubscriptionNameKey] as string);
 }
Ejemplo n.º 19
0
 internal static void SetSubscriptionName(this AbstractConsumerSettings consumerSettings, string subscriptionName)
 {
     consumerSettings.Properties[SubscriptionNameKey] = subscriptionName;
 }
 public RedisChannelConsumer(AbstractConsumerSettings consumerSettings, ISubscriber subscriber, IMessageProcessor <byte[]> messageProcessor)
 {
     _channelMessageQueue = subscriber.Subscribe(consumerSettings.Topic);
     _channelMessageQueue.OnMessage(m => messageProcessor.ProcessMessage(m.Message));
 }