private async Task <IEnumerable <DeadLetter> > ReadDeadLettersFromServiceBusAsync(string serviceBusQueue)
        {
            ConcurrentBag <DeadLetter> _deadLetters = new ConcurrentBag <DeadLetter>();

            IMessageReceiver messageReceiver = _messageReceiverFactory.Create(serviceBusQueue, ReceiveMode.PeekLock, true);

            IList <Message> messages = await messageReceiver.PeekAsync(MaxMessageCount);

            await messageReceiver.CloseAsync();

            foreach (Message message in messages)
            {
                // Process the message
                var deadletter = new DeadLetter(_messageReader.ReadMessage(Encoding.UTF8.GetString(message.Body)))
                {
                    MessageDate                = message.SystemProperties.EnqueuedTimeUtc,
                    DeadLetterReason           = message.UserProperties["DeadLetterReason"].ToString(),
                    DeadLetterErrorDescription = message.UserProperties["DeadLetterErrorDescription"].ToString(),
                    SequenceNumber             = message.SystemProperties.SequenceNumber,
                    SubscriptionName           = serviceBusQueue
                };

                _deadLetters.Add(deadletter);
            }

            return(_deadLetters);
        }
예제 #2
0
        private void CreateMessageReceiver(string queueName, int?prefetch = null)
        {
            if (_messageReceiver != null)
            {
                return;
            }

            lock (_padlock)
            {
                if (_messageReceiver != null)
                {
                    return;
                }

                _messageReceiver = _messageReceiverFactory.Create(queueName);

                if (prefetch.HasValue)
                {
                    _messageReceiver.PrefetchCount = prefetch.Value;
                }
            }
        }