예제 #1
0
        /// <summary>
        /// Will pass an incoming message to the <see cref="Receiver"/> for processing.
        /// </summary>
        /// <param name="messageSession">Contains the MessageSession when sessions are enabled.</param>
        /// <param name="message"></param>
        protected async Task ReceiveMessageAsync(BrokeredMessage message, MessageSession messageSession)
        {
            try
            {
                ProcessingMessage.Reset();
                await Receiver.ReceiveMessageAsync(message, messageSession, StopProcessingMessageToken);

                if (Receiver.AutoComplete)
                {
                    await message.CompleteAsync();
                }
            }
            finally
            {
                message.Dispose();
                ProcessingMessage.Set();
            }
        }
        /// <summary>
        /// Processes the provided set of <see cref="BrokeredMessage"/>s, with optional automatic lock renewal.
        /// </summary>
        /// <param name="messageSession">Contains the MessageSession when sessions are enabled.</param>
        /// <param name="messages"></param>
        /// <returns></returns>
        private async Task ProcessMessagesAsync(ICollection <BrokeredMessage> messages, MessageSession messageSession)
        {
            WriteLog($"Service Bus Communication Listnener processing {messages.Count} messages.");

            using (CreateRenewTimer(messages))
            {
                try
                {
                    ProcessingMessage.Reset();
                    await BatchReceiver.ReceiveMessagesAsync(messages, messageSession, StopProcessingMessageToken);
                }
                finally
                {
                    foreach (var message in messages)
                    {
                        message.Dispose();
                    }
                    ProcessingMessage.Set();
                }
            }
        }