示例#1
0
        public MessageQueueSubscriber(string hostId, MessageDispatchInfo dispatchInfo)
        {
            if (string.IsNullOrWhiteSpace(hostId))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(hostId));
            }

            if (dispatchInfo == null)
            {
                throw new ArgumentNullException(nameof(dispatchInfo));
            }

            _hostId = hostId;

            // Obtain the subscriber attribute so the definition metadata
            // can be retrieved.
            var queueAttribute = dispatchInfo.MessageHandlerMethod
                                 .GetCustomAttribute <SubscriberQueueAttribute>();

            DispatchInfo           = dispatchInfo;
            QueueMeta              = queueAttribute.QueueFactory.CreateQueueMeta(queueAttribute);
            QueueMeta.QueueFactory = queueAttribute.QueueFactory;

            ApplyScopedQueueName(QueueMeta);
        }
示例#2
0
        protected override Task <IQueue> QueueDeclareAsync(IBus bus, QueueMeta queueMeta)
        {
            CreatedQueues.Add(queueMeta);

            var mockQueue = new Mock <IQueue>();

            return(Task.FromResult(mockQueue.Object));
        }
示例#3
0
        private void ApplyScopedQueueName(QueueMeta meta)
        {
            if (meta.AppendHostId)
            {
                meta.SetScopedName($"{meta.QueueName}->({_hostId})");
            }

            if (meta.AppendUniqueId)
            {
                meta.SetScopedName($"{meta.QueueName}<-({Guid.NewGuid()})");
            }
        }
示例#4
0
        public void ApplyQueueSettings(QueueMeta meta)
        {
            if (meta == null)
            {
                throw new ArgumentNullException(nameof(meta));
            }

            var queueSettings = GetQueueSettings(meta.Exchange.BusName, meta.QueueName);

            if (queueSettings != null)
            {
                meta.ApplyOverrides(queueSettings);
            }

            ApplyExchangeSettingsInternal(meta.Exchange, applyQueueSettings: false);
        }
示例#5
0
        // Defines a callback function to be called when a message arrives on the queue.
        protected virtual void ConsumeMessageQueue(IBus bus, IQueue queue, MessageQueueSubscriber subscriber)
        {
            QueueMeta definition = subscriber.QueueMeta;

            bus.Advanced.Consume(queue,
                                 (bytes, msgProps, receiveInfo) =>
            {
                var consumerContext = new ConsumeContext
                {
                    Logger               = Context.LoggerFactory.CreateLogger(definition.QueueFactory.GetType().FullName),
                    MessageData          = bytes,
                    MessageProps         = msgProps,
                    MessageReceiveInfo   = receiveInfo,
                    Subscriber           = subscriber,
                    BusModule            = BusModule,
                    MessagingModule      = MessagingModule,
                    Serialization        = _serializationManager,
                    GetRpcMessageHandler = GetRpcMessageHandler
                };

                // Delegate to the queue factory, associated with the definition, and
                // allow it to determine how the received message should be processed.
                return(definition.QueueFactory.OnMessageReceivedAsync(consumerContext));
            },
                                 config =>
            {
                if (definition.PrefetchCount > 0)
                {
                    config.WithPrefetchCount(definition.PrefetchCount);
                }

                if (definition.IsExclusive)
                {
                    config.AsExclusive();
                }

                config.WithPriority(definition.Priority);
            });
        }
示例#6
0
        public QueueMeta CreateQueueMeta(SubscriberQueueAttribute attribute)
        {
            var exchange = ExchangeMeta.Define(attribute.BusName, attribute.ExchangeName, ExchangeType.Fanout,
                                               config =>
            {
                config.IsAutoDelete = true;
                config.IsDurable    = false;
                config.IsPassive    = false;
                config.IsPersistent = false;
            });

            var queue = QueueMeta.Define(attribute.QueueName, exchange,
                                         config =>
            {
                config.IsAutoDelete   = true;
                config.IsDurable      = false;
                config.IsPassive      = false;
                config.IsExclusive    = true;
                config.AppendUniqueId = true;
            });

            return(queue);
        }
示例#7
0
 protected virtual Task <IQueue> QueueDeclareAsync(IBus bus, QueueMeta queueMeta)
 {
     return(bus.Advanced.QueueDeclare(queueMeta));
 }