Esempio n. 1
0
        public async Task DeadLetters_A_Message_Given_Correctly_Configured_TopicHandlingOptions_And_Result_Is_Errored_When_Handling_Messages()
        {
            _mockProcessor.Reset();
            _mockProcessor
            .Setup(m => m.ProcessMessageAsync(It.IsAny <Message>(), _options, CancellationToken.None))
            .ReturnsAsync(MessageHandlingResult.DeadLettered(new DivideByZeroException()));

            await _listener.StartListeningAsync(CancellationToken.None).ConfigureAwait(false);

            await ReceiveMessages(1).ConfigureAwait(false);

            _spyMessageReceiver.DeadLetterAsyncCalled.Should().BeTrue();
        }
Esempio n. 2
0
        public void Return_Expected_Result_Using_DeadLetteredMessageType_Helper_Given_Details_And_AdditionalProperties(
            string details, string additionalPropertyKey, string additionalPropertyValue)
        {
            var additionalProperties = new Dictionary <string, object>
            {
                { additionalPropertyKey, additionalPropertyValue }
            };
            var result = MessageHandlingResult.DeadLettered(details, additionalProperties);

            result.Result.Should().Be(MessageHandlingResult.HandlingResult.DeadLettered);
            result.AdditionalProperties["AzureBusDepot.DeadLettered"].Should().Be(details);
            result.AdditionalProperties[additionalPropertyKey].Should().Be(additionalPropertyValue);
            result.AdditionalProperties.Count.Should().Be(2);
        }
Esempio n. 3
0
        public void Return_Expected_Result_Using_DeadLetteredMessageType_Helper_Given_Exception_And_AdditionalProperties(
            string additionalPropertyKey, string additionalPropertyValue)
        {
            var exception            = new MessageSizeExceededException("That's no moon");
            var additionalProperties = new Dictionary <string, object>
            {
                { additionalPropertyKey, additionalPropertyValue }
            };
            var result = MessageHandlingResult.DeadLettered(exception, additionalProperties);

            result.Result.Should().Be(MessageHandlingResult.HandlingResult.DeadLettered);
            result.AdditionalProperties["AzureBusDepot.DeadLettered"].Should().Be("Exception");
            result.AdditionalProperties["AzureBusDepot.Exception.Message"].Should().Be(exception.Message);
            result.AdditionalProperties[additionalPropertyKey].Should().Be(additionalPropertyValue);
            result.AdditionalProperties.Count.Should().Be(4);
        }
        public async Task <MessageHandlingResult> HandleMessageAsync(
            MySecondCommand message, MessageContext context, CancellationToken ct)
        {
            _logger.LogDebug(LogEventIds.HandlerStarted, $"{nameof(MySecondCommandHandler)}:{nameof(HandleMessageAsync)} started");

            try
            {
                await FakeCallToPersistToSomeDatabase(message, ct);
            }
            catch (Exception ex)
            {
                _logger.LogError(LogEventIds.HandlerException, ex, $"Unhandled exception in {nameof(MySecondCommandHandler)}");
                return(MessageHandlingResult.DeadLettered(ex, context.UserProperties));
            }

            _logger.LogDebug(LogEventIds.HandlerFinished, $"{nameof(MySecondCommandHandler)}:{nameof(HandleMessageAsync)} finished");

            return(MessageHandlingResult.Completed(context.UserProperties));
        }
        public async Task <MessageHandlingResult> HandleMessageAsync(
            MyFirstCommand message, MessageContext context, CancellationToken ct)
        {
            _logger.LogDebug(LogEventIds.HandlerStarted, $"{nameof(MyFirstCommandHandler)}:{nameof(HandleMessageAsync)} started");

            try
            {
                await FakeCallToHttpApiToPutAssociatedItem(message, ct).ConfigureAwait(false);

                await FakeSendingOfMessage(message, ct).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                _logger.LogError(LogEventIds.HandlerException, ex, $"Unhandled exception in {nameof(MyFirstCommandHandler)}");
                return(MessageHandlingResult.DeadLettered(ex, context.UserProperties));
            }

            _logger.LogDebug(LogEventIds.HandlerFinished, $"{nameof(MyFirstCommandHandler)}:{nameof(HandleMessageAsync)} finished");

            return(MessageHandlingResult.Completed(context.UserProperties));
        }
Esempio n. 6
0
        public async Task <MessageHandlingResult> HandleMessageAsync(
            MyEvent message, MessageContext context, CancellationToken ct)
        {
            _logger.LogDebug(LogEventIds.HandlerStarted, $"{nameof(MyEventHandler)}:{nameof(HandleMessageAsync)} started");

            try
            {
                // Just some fake tasks to mimic doing something
                var associatedItem = await FakeCallToHttpApiToGetAssociatedItem(message, ct).ConfigureAwait(false);

                var dbContractItem = (message.Id, message.Name, associatedItem.Id, associatedItem.Name);

                await FakeCallToPersistToSomeDatabase(dbContractItem, ct);
            }
            catch (DivideByZeroException ex)
            {
                _logger.LogError(LogEventIds.HandlerException, ex, $"Unhandled exception in {nameof(MyEventHandler)}");
                return(MessageHandlingResult.DeadLettered(ex, context.UserProperties));
            }

            _logger.LogDebug(LogEventIds.HandlerFinished, $"{nameof(MyEventHandler)}:{nameof(HandleMessageAsync)} finished");

            return(MessageHandlingResult.Completed(context.UserProperties));
        }
Esempio n. 7
0
        public async Task Track_Request_Telemetry_When_Handling_Messages(int count, bool isSuccessful, string customProperty)
        {
            var customProperties = new Dictionary <string, object> {
                { "customProperty", customProperty }
            };

            _mockProcessor.Reset();
            _mockProcessor
            .Setup(m => m.ProcessMessageAsync(It.IsAny <Message>(), _options, CancellationToken.None))
            .ReturnsAsync(isSuccessful ? MessageHandlingResult.Completed(customProperties) : MessageHandlingResult.DeadLettered("BOOM", customProperties));

            await _listener.StartListeningAsync(CancellationToken.None).ConfigureAwait(false);

            await ReceiveMessages(count).ConfigureAwait(false);

            _mockInstrumentor.Verify(
                i => i.TrackRequest(
                    LogEventIds.ListenerHandlerFinished, It.IsAny <long>(), It.IsAny <DateTimeOffset>(), "MultiMessageTypeListener<MyEndpointHandlingConfig>", null, null, isSuccessful, It.Is <IDictionary <string, object> >(d => (string)d["customProperty"] == customProperty)),
                Times.Exactly(count));
        }