/// <summary>
        /// Get all messages that has a session
        /// </summary>
        /// <param name="client">QueueClient</param>
        private void GetSessionMessages(QueueClient client)
        {
            try
            {
                MessageSession ses = client.AcceptMessageSession(properties.Session);

                BrokeredMessage item = ses.Receive(properties.ReceiveTimeout);

                while (true)
                {
                    if (item == null)
                    {
                        break;
                    }

                    if (SubmitMessage(item) == false)
                    {
                        ses.Abort();
                        break;
                    }

                    //allow setting timeout
                    item = ses.Receive(properties.ReceiveTimeout);
                }
            }
            catch (Exception)
            {
                //probably lock
            }
        }
        /// <summary>
        /// Get all messages with a specific session
        /// </summary>
        /// <param name="client">QueueClient</param>
        private void GetAllMessagesWithSession(QueueClient client)
        {
            foreach (MessageSession sessions in client.GetMessageSessions())
            {
                try
                {
                    MessageSession ses = client.AcceptMessageSession(sessions.SessionId);

                    BrokeredMessage item = ses.Receive(properties.ReceiveTimeout);

                    while (true)
                    {
                        if (item == null)
                        {
                            break;
                        }

                        if (SubmitMessage(item) == false)
                        {
                            ses.Abort();
                            break;
                        }
                        //allow setting timeout
                        item = ses.Receive(properties.ReceiveTimeout);
                    }
                }
                catch (Exception)
                {
                    break;
                }
            }
        }
        public async Task OnMessageAsync(MessageSession session, BrokeredMessage message)
        {
            try
            {
                ServiceBusEventSource.Log.SessionMessageReceived(_receiverNamespace, _receiverPath, session.SessionId, message.MessageId, message.CorrelationId);

                // Handle the message.
                await _messageHandler(session, message);
            }
            catch (Exception exception)
            {
                ServiceBusEventSource.Log.SessionMessageReceiverException(_receiverNamespace, _receiverPath, session.SessionId, message.MessageId, message.CorrelationId, "OnMessage", exception.Message, exception.StackTrace);

                // Don't allow other messages to be processed.
                if (_options.RequireSequentialProcessing)
                {
                    message.Abandon();
                    session.Abort();
                }

                throw;
            }
        }
        public async Task OnMessageAsync(MessageSession session, BrokeredMessage message)
        {
            try
            {
                ServiceBusEventSource.Log.SessionMessageReceived(_receiverNamespace, _receiverPath, message.MessageId, message.CorrelationId, message.SessionId, message.DeliveryCount, message.Size);

                // Handle the message.
                await _messageHandler(session, message)
                    .ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                ServiceBusEventSource.Log.MessagePumpExceptionReceived(_receiverNamespace, _receiverPath, "OnSessionMessage", exception);

                // Don't allow other messages to be processed.
                if (_options.RequireSequentialProcessing)
                {
                    message.Abandon();
                    session.Abort();
                }

                throw;
            }
        }
Exemple #5
0
        public async Task OnMessageAsync(MessageSession session, BrokeredMessage message)
        {
            try
            {
                ServiceBusEventSource.Log.SessionMessageReceived(_receiverNamespace, _receiverPath, message.MessageId, message.CorrelationId, message.SessionId, message.DeliveryCount, message.Size);

                // Handle the message.
                await _messageHandler(session, message)
                .ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                ServiceBusEventSource.Log.MessagePumpExceptionReceived(_receiverNamespace, _receiverPath, "OnSessionMessage", exception);

                // Don't allow other messages to be processed.
                if (_options.RequireSequentialProcessing)
                {
                    message.Abandon();
                    session.Abort();
                }

                throw;
            }
        }