Пример #1
0
        async Task OnMessageHandlerAsync(
            OnMessageOptions onMessageOptions,
            Func <BrokeredMessage, CancellationToken, Task> callback)
        {
            MessagingEventSource.Log.RegisterOnMessageHandlerStart(this.ClientId, onMessageOptions);

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

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

            try
            {
                await this.receivePump.StartPumpAsync().ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                MessagingEventSource.Log.RegisterOnMessageHandlerException(this.ClientId, exception);

                this.receivePumpCancellationTokenSource.Cancel();
                this.receivePumpCancellationTokenSource.Dispose();
                this.receivePump = null;
                throw;
            }

            MessagingEventSource.Log.RegisterOnMessageHandlerStop(this.ClientId);
        }
Пример #2
0
 public void RegisterOnMessageHandlerStart(string clientId, OnMessageOptions onMessageOptions)
 {
     if (this.IsEnabled())
     {
         this.RegisterOnMessageHandlerStart(clientId, onMessageOptions.AutoComplete, onMessageOptions.AutoRenewLock, onMessageOptions.MaxConcurrentCalls, (long)onMessageOptions.AutoRenewTimeout.TotalSeconds);
     }
 }
Пример #3
0
        public MessageReceivePump(
            MessageReceiver messageReceiver,
            OnMessageOptions onMessageOptions,
            Func <BrokeredMessage, CancellationToken, Task> callback,
            CancellationToken pumpCancellationToken)
        {
            if (messageReceiver == null)
            {
                throw new ArgumentNullException(nameof(messageReceiver));
            }

            this.messageReceiver                 = messageReceiver;
            this.onMessageOptions                = onMessageOptions;
            this.onMessageCallback               = callback;
            this.pumpCancellationToken           = pumpCancellationToken;
            this.maxConcurrentCallsSemaphoreSlim = new SemaphoreSlim(this.onMessageOptions.MaxConcurrentCalls);
        }
Пример #4
0
 /// <summary>Asynchronously processes a message.</summary>
 /// <param name="callback">The method to invoke when the operation is complete.</param>
 /// <param name="onMessageOptions">Calls a message option.</param>
 public void OnMessageAsync(Func <BrokeredMessage, CancellationToken, Task> callback, OnMessageOptions onMessageOptions)
 {
     this.InnerReceiver.OnMessageAsync(callback, onMessageOptions);
 }
Пример #5
0
 public void OnMessageAsync(Func <BrokeredMessage, CancellationToken, Task> callback, OnMessageOptions onMessageOptions)
 {
     onMessageOptions.ReceiveTimeOut = this.OperationTimeout;
     this.OnMessageHandlerAsync(onMessageOptions, callback).GetAwaiter().GetResult();
 }