private static Func <ExceptionReceivedEventArgs, Task> GetExceptionReceivedHandler(
            MessageHandlerOptions options)
        {
            if (options?.ExceptionReceivedHandler == null)
            {
                return(_ => Task.CompletedTask);
            }

            Task ExceptionReceivedHandler(ExceptionReceivedEventArgs args)
            {
                var context = new MessageHandlerExceptionContext(args.Exception);

                return(options.ExceptionReceivedHandler(new MessageHandlerExceptionContext(args.Exception)));
            }

            return(ExceptionReceivedHandler);
        }
        public override Task RegisterMessageHandler(
            Func <IQueueMessage, CancellationToken, Task> messageHandler,
            MessageHandlerOptions messageHandlerOptions)
        {
            if (messageHandlerOptions == null)
            {
                throw new ArgumentNullException(nameof(messageHandlerOptions));
            }

            var exceptionReceivedHandler = GetExceptionReceivedHandler(messageHandlerOptions);

            var options = new Microsoft.Azure.ServiceBus.MessageHandlerOptions(exceptionReceivedHandler)
            {
                AutoComplete         = messageHandlerOptions.AutoComplete,
                MaxConcurrentCalls   = messageHandlerOptions.MaxConcurrentCalls,
                MaxAutoRenewDuration = TimeSpan.FromMinutes(5)
            };

            _messageReceiver.RegisterMessageHandler(
                (message, token) => messageHandler(new AzureServiceBusQueueMessage(message), token),
                options);

            return(Task.CompletedTask);
        }
Beispiel #3
0
 public abstract Task RegisterMessageHandler(
     Func <IQueueMessage, CancellationToken, Task> messageHandler,
     MessageHandlerOptions messageHandlerOptions);