public async Task <MessageHandlingResult> ProcessMessageAsync( Message message, IEndpointHandlingConfig handlingConfig, CancellationToken ct) { try { var messageContext = MessageContext.Create(message); var contractMessage = _serialiser.Deserialise <TMessage>(message); if (contractMessage == null) { return(MessageHandlingResult.UnrecognisedMessageType( $"Serialiser could not de-serialise message to {typeof(TMessage).AssemblyQualifiedName}", message.UserProperties)); } var stopwatch = Stopwatch.StartNew(); var handlingResult = await _handler.HandleMessageAsync(contractMessage, messageContext, ct).ConfigureAwait(false); _instrumentor.TrackElapsed( LogEventIds.HandlerMeasuredElapsed, stopwatch.ElapsedMilliseconds, _handler.GetType().Name, message.UserProperties); return(handlingResult); } catch (OperationCanceledException ex) { _logger.LogWarning(LogEventIds.ProcessorCancelled, ex, $"Operation was cancelled in Processor<{typeof(TMessage).Name}>"); return(MessageHandlingResult.Abandoned(ex, message.UserProperties)); } }
public async Task DeadLetters_A_Message_Given_Correctly_Configured_TopicHandlingOptions_And_Result_Is_UnrecognisedMessageType_When_Handling_Messages() { _mockProcessor.Reset(); _mockProcessor .Setup(m => m.ProcessMessageAsync(It.IsAny <Message>(), _options, CancellationToken.None)) .ReturnsAsync(MessageHandlingResult.UnrecognisedMessageType("Bad ting")); await _listener.StartListeningAsync(CancellationToken.None).ConfigureAwait(false); await ReceiveMessages(1).ConfigureAwait(false); _spyMessageReceiver.DeadLetterAsyncCalled.Should().BeTrue(); }
public void Return_Expected_Result_Using_UnrecognisedMessageType_Helper_Given_Details_And_AdditionalProperties( string details, string additionalPropertyKey, string additionalPropertyValue) { var additionalProperties = new Dictionary <string, object> { { additionalPropertyKey, additionalPropertyValue } }; var result = MessageHandlingResult.UnrecognisedMessageType(details, additionalProperties); result.Result.Should().Be(MessageHandlingResult.HandlingResult.UnrecognisedMessageType); result.AdditionalProperties["AzureBusDepot.UnrecognisedMessageType"].Should().Be(details); result.AdditionalProperties[additionalPropertyKey].Should().Be(additionalPropertyValue); result.AdditionalProperties.Count.Should().Be(2); }