Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

Commit

Permalink
Fix Deserialization Bug In Sqs Consumer (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
regis-duhirwe-cko authored Nov 14, 2020
1 parent 92d2f08 commit 62bcfac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
22 changes: 15 additions & 7 deletions src/OpenMessage.AWS.SQS/SqsConsumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,22 @@ public async Task<List<SqsMessage<T>>> ConsumeAsync(CancellationToken cancellati
if (_acknowledgementAction is null)
Throw.Exception("Acknowledgement action cannot be null for SQS message");

result.Add(new SqsMessage<T>(_acknowledgementAction)
try
{
result.Add(new SqsMessage<T>(_acknowledgementAction)
{
Id = message.MessageId,
Properties = properties,
ReceiptHandle = message.ReceiptHandle,
QueueUrl = _currentConsumerOptions.QueueUrl,
Value = _deserializationProvider.From<T>(message.Body, contentType, messageType ?? string.Empty)
});
}
catch (Exception e)
{
Id = message.MessageId,
Properties = properties,
ReceiptHandle = message.ReceiptHandle,
QueueUrl = _currentConsumerOptions.QueueUrl,
Value = _deserializationProvider.From<T>(message.Body, contentType, messageType ?? string.Empty)
});
// Swallow deserialization exception to prevent blocking the pipeline and processing of subsequent messages.
_logger.LogError(e,$"Error deserializing message body. {e.Message}. {nameof(message.MessageId)}:{message.MessageId}. {nameof(message.MD5OfBody)}:{message.MD5OfBody}");
}
}

return result;
Expand Down
10 changes: 5 additions & 5 deletions tests/OpenMessage.Tests/Pipelines/BatcherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ await Task.WhenAll(Enumerable.Range(0, _batchSize - 1)

Assert.Equal(1, _history.Count);

Assert.Equal(_batchSize - 1, _history.Single()
.Count);
Assert.True(stopwatch.Elapsed >= _timeout);
Assert.Equal(_batchSize - 1, _history.Single().Count);

Assert.True(stopwatch.Elapsed.Add(TimeSpan.FromMilliseconds(5)) >= _timeout);
}

[Fact]
Expand All @@ -49,8 +49,8 @@ await Task.WhenAll(Enumerable.Range(0, _batchSize)

Assert.Equal(1, _history.Count);

Assert.Equal(_batchSize, _history.Single()
.Count);
Assert.Equal(_batchSize, _history.Single().Count);

Assert.True(stopwatch.Elapsed < _timeout);
}

Expand Down

0 comments on commit 62bcfac

Please sign in to comment.