public void Send(IBrokeredMessage message)
 {
     _callback.Invoke(message);
     if (_onMessageOptions.AutoComplete)
     {
         message.Complete();
     }
 }
示例#2
0
        private void HandleMessageResult(SubscriberInfo subscriberInfo, ServiceBusMessageStates state, IBrokeredMessage brokeredMessage, string messageBody)
        {
            _logService.Debug("Handling message id '{0}', topic/subscription '{1}', state '{2}', body '{3}' ",
                              brokeredMessage.MessageId, subscriberInfo.SubscriptionPath, state, messageBody);

            switch (state)
            {
            case ServiceBusMessageStates.Complete:
                brokeredMessage.Complete();
                break;

            case ServiceBusMessageStates.Abandon:
                brokeredMessage.Abandon();
                break;

            case ServiceBusMessageStates.DeadLetter:
                brokeredMessage.DeadLetter();
                break;

            case ServiceBusMessageStates.Requeue:
                var scheduledEnqueueTimeUtc = brokeredMessage.ScheduledEnqueueTimeUtc == DateTime.MinValue ? DateTime.UtcNow.AddSeconds(30) : GetDefaultRequeueDateTimeUtc();

                var newBrokeredMessage = new BrokeredMessage(messageBody)
                {
                    ScheduledEnqueueTimeUtc = scheduledEnqueueTimeUtc
                };

                subscriberInfo.TopicClient.Send(newBrokeredMessage);
                brokeredMessage.Complete();
                break;

            default:
                var deadLetterReason = string.Format(
                    "Invalid message state '{0}' for message id '{1}', topic/subscription '{2}': message will be dead-lettered",
                    state, brokeredMessage.MessageId, subscriberInfo.SubscriptionPath);

                _logService.Error(deadLetterReason);

                brokeredMessage.DeadLetter();
                break;
            }

            _logService.Debug("Handled message id '{0}', topic/subscription '{1}', state '{2}', body '{3}' ",
                              brokeredMessage.MessageId, subscriberInfo.SubscriptionPath, state, messageBody);
        }
示例#3
0
        static bool SafeComplete(IBrokeredMessage msg)
        {
            try {
                // Mark brokered message as complete.
                msg.Complete();

                // Return a result indicating that the message has been completed successfully.
                return(true);
            }
            catch (MessageLockLostException) {
                // It's too late to compensate the loss of a message lock. We should just ignore it so that it does not break the receive loop.
                // We should be prepared to receive the same message again.
            }
            catch (MessagingException) {
                // There is nothing we can do as the connection may have been lost, or the underlying topic/subscription may have been removed.
                // If Complete() fails with this exception, the only recourse is to prepare to receive another message (possibly the same one).
            }

            return(false);
        }
        static bool SafeComplete(IBrokeredMessage msg) {
            try {
                // Mark brokered message as complete.
                msg.Complete();

                // Return a result indicating that the message has been completed successfully.
                return true;
            }
            catch (MessageLockLostException) {
                // It's too late to compensate the loss of a message lock. We should just ignore it so that it does not break the receive loop.
                // We should be prepared to receive the same message again.
            }
            catch (MessagingException) {
                // There is nothing we can do as the connection may have been lost, or the underlying topic/subscription may have been removed.
                // If Complete() fails with this exception, the only recourse is to prepare to receive another message (possibly the same one).
            }

            return false;
        }