Beispiel #1
0
        async Task OnMessageHandlerAsync(
            RegisterHandlerOptions registerHandlerOptions,
            Func <Message, CancellationToken, Task> callback)
        {
            MessagingEventSource.Log.RegisterOnMessageHandlerStart(this.ClientId, registerHandlerOptions);

            lock (this.messageReceivePumpSyncLock)
            {
                if (this.receivePump != null)
                {
                    throw new InvalidOperationException(Resources.OnMessageAlreadyCalled);
                }

                this.receivePumpCancellationTokenSource = new CancellationTokenSource();
                this.receivePump = new MessageReceivePump(this, registerHandlerOptions, callback, this.receivePumpCancellationTokenSource.Token);
            }

            try
            {
                await this.receivePump.StartPumpAsync().ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                MessagingEventSource.Log.RegisterOnMessageHandlerException(this.ClientId, exception);
                lock (this.messageReceivePumpSyncLock)
                {
                    if (this.receivePump != null)
                    {
                        this.receivePumpCancellationTokenSource.Cancel();
                        this.receivePumpCancellationTokenSource.Dispose();
                        this.receivePump = null;
                    }
                }

                throw;
            }

            MessagingEventSource.Log.RegisterOnMessageHandlerStop(this.ClientId);
        }
Beispiel #2
0
 public void RegisterMessageHandler(Func <Message, CancellationToken, Task> handler, RegisterHandlerOptions registerHandlerOptions)
 {
     registerHandlerOptions.ReceiveTimeOut = this.OperationTimeout;
     this.OnMessageHandlerAsync(registerHandlerOptions, handler).GetAwaiter().GetResult();
 }
Beispiel #3
0
 public virtual void RegisterMessageHandler(Func <TWrapper, CancellationToken, Task> handler,
                                            RegisterHandlerOptions handlerOptions)
 {
     QueueClient.RegisterMessageHandler((message, token) => Handler(message, token, handler), handlerOptions);
 }