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); }
protected override Task <IQueue> QueueDeclareAsync(IBus bus, QueueMeta queueMeta) { CreatedQueues.Add(queueMeta); var mockQueue = new Mock <IQueue>(); return(Task.FromResult(mockQueue.Object)); }
private void ApplyScopedQueueName(QueueMeta meta) { if (meta.AppendHostId) { meta.SetScopedName($"{meta.QueueName}->({_hostId})"); } if (meta.AppendUniqueId) { meta.SetScopedName($"{meta.QueueName}<-({Guid.NewGuid()})"); } }
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); }
// 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); }); }
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); }
protected virtual Task <IQueue> QueueDeclareAsync(IBus bus, QueueMeta queueMeta) { return(bus.Advanced.QueueDeclare(queueMeta)); }