public Task StartAsync(OnMessage messageHandler, OnMessageException exceptionHandler, OnMessageOptions options) { lock (_initializationLock) { if (_initialized) { throw new MessageReceiverException("Message receiver has already been initialized."); } if (messageHandler == null) { throw new ArgumentNullException("messageHandler"); } if (options == null) { options = _defaultOptions; } // Log. ServiceBusEventSource.Log.MessagePumpStart(GetType().Name, Namespace, Path, options.AutoRenewTimeout, options.MaxConcurrentCalls); // Initialize the handler options. var messageOptions = new Microsoft.ServiceBus.Messaging.OnMessageOptions(); messageOptions.AutoComplete = options.AutoComplete; messageOptions.AutoRenewTimeout = options.AutoRenewTimeout; messageOptions.MaxConcurrentCalls = options.MaxConcurrentCalls; messageOptions.ExceptionReceived += (s, e) => { if (e.Exception != null) { // Log. ServiceBusEventSource.Log.MessagePumpExceptionReceived(Namespace, Path, e.Action, e.Exception); // Handle exception. if (exceptionHandler != null) { exceptionHandler(e.Action, e.Exception); } } }; // Mark receiver as initialized. _initialized = true; // Start. return(OnStartAsync(messageHandler, messageOptions)); } }
public Task StartAsync(OnMessage messageHandler, OnMessageException exceptionHandler, OnMessageOptions options) { lock (_initializationLock) { if (_initialized) throw new MessageReceiverException("Message receiver has already been initialized."); if (messageHandler == null) throw new ArgumentNullException("messageHandler"); if (options == null) options = _defaultOptions; // Log. ServiceBusEventSource.Log.MessagePumpStart(GetType().Name, Namespace, Path, options.AutoRenewTimeout, options.MaxConcurrentCalls); // Initialize the handler options. var messageOptions = new Microsoft.ServiceBus.Messaging.OnMessageOptions(); messageOptions.AutoComplete = options.AutoComplete; messageOptions.AutoRenewTimeout = options.AutoRenewTimeout; messageOptions.MaxConcurrentCalls = options.MaxConcurrentCalls; messageOptions.ExceptionReceived += (s, e) => { if (e.Exception != null) { // Log. ServiceBusEventSource.Log.MessagePumpExceptionReceived(Namespace, Path, e.Action, e.Exception); // Handle exception. if (exceptionHandler != null) exceptionHandler(e.Action, e.Exception); } }; // Mark receiver as initialized. _initialized = true; // Start. return OnStartAsync(messageHandler, messageOptions); } }
/// <summary> /// Start the handler. /// </summary> /// <returns></returns> internal override Task OnStartAsync(OnMessage messageHandler, Microsoft.ServiceBus.Messaging.OnMessageOptions messageOptions) { _client.OnMessageAsync(msg => HandleMessage(messageHandler, msg), messageOptions); return(Task.FromResult(false)); }
internal abstract Task OnStartAsync(OnMessage messageHandler, Microsoft.ServiceBus.Messaging.OnMessageOptions messageOptions);