private void AddQueueHandler(string queueName) { #if NETSTANDARD2_0 var sbClient = new QueueClient(address, queueName, ReceiveMode.PeekLock); var sbWorker = new ServiceBusMqWorker(this, CreateMessageQueueClient(), queueName, sbClient); sbClient.RegisterMessageHandler(sbWorker.HandleMessageAsync, new MessageHandlerOptions( (eventArgs) => Task.CompletedTask) { MaxConcurrentCalls = 1, AutoComplete = false }); #else var options = new OnMessageOptions { // Cannot use AutoComplete because our HandleMessage throws errors into SS's handlers; this would // normally release the BrokeredMessage back to the Azure Service Bus queue, which we don't actually want AutoComplete = false, //AutoRenewTimeout = new TimeSpan() MaxConcurrentCalls = 1 }; var sbClient = QueueClient.CreateFromConnectionString(address, queueName, ReceiveMode.PeekLock); var sbWorker = new ServiceBusMqWorker(this, CreateMessageQueueClient(), queueName, sbClient); sbClient.OnMessage(sbWorker.HandleMessage, options); #endif sbClients.GetOrAdd(queueName, sbClient); }
protected internal void StartQueues(Dictionary <Type, IMessageHandlerFactory> handlerMap) { // Create queues for each registered type this.handlerMap = handlerMap; queueMap = new Dictionary <string, Type>(); var queues = new [] { ".inq", ".outq", ".priorityq", ".dlq" }; foreach (var type in this.handlerMap.Keys) { foreach (string q in queues) { string queueName = type.Name + q; if (!queueMap.ContainsKey(queueName)) { queueMap.Add(queueName, type); } #if !NETSTANDARD1_6 QueueDescription qd = new QueueDescription(queueName); if (!namespaceManager.QueueExists(queueName)) { namespaceManager.CreateQueue(qd); } #endif #if NETSTANDARD1_6 var sbClient = new QueueClient(address, queueName, ReceiveMode.PeekLock); var sbWorker = new ServiceBusMqWorker(this, CreateMessageQueueClient(), queueName, sbClient); sbClient.RegisterMessageHandler(sbWorker.HandleMessageAsync, new MessageHandlerOptions( (eventArgs) => { return(Task.CompletedTask); } ) { MaxConcurrentCalls = 1 } ); sbClients.Add(queueName, sbClient); #else var options = new OnMessageOptions { // Cannot use AutoComplete because our HandleMessage throws errors into SS's handlers; this would // normally release the BrokeredMessage back to the Azure Service Bus queue, which we don't actually want //AutoComplete = true, //AutoRenewTimeout = new TimeSpan() MaxConcurrentCalls = 1 }; var sbClient = QueueClient.CreateFromConnectionString(address, qd.Path, ReceiveMode.PeekLock); var sbWorker = new ServiceBusMqWorker(this, CreateMessageQueueClient(), queueName, sbClient); sbClient.OnMessage(sbWorker.HandleMessage, options); sbClients.Add(qd.Path, sbClient); #endif } } }