Skip to content

Commit

Permalink
Crude idea of how S3 fallback could work
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Yaxley committed Jul 26, 2018
1 parent c21e58b commit aadb7eb
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion Rebus.AmazonSQS/AmazonSQS/AmazonSqsTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Globalization;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Amazon.Runtime;
Expand Down Expand Up @@ -283,7 +284,21 @@ await Task.WhenAll(
var sqsMessage = new AmazonSQSTransportMessage(transportMessage.Headers, GetBody(transportMessage.Body));
var entry = new SendMessageBatchRequestEntry(messageId, _serializer.Serialize(sqsMessage));
var serializedSqsMessage = _serializer.Serialize(sqsMessage);
var serializedSqsMessageByteCount = Encoding.UTF8.GetByteCount(serializedSqsMessage);
SendMessageBatchRequestEntry entry;
if (serializedSqsMessageByteCount > 256 * 1024)
{
headers.Add("rebus-sqs-s3-fallback", "true");
// upload message to S3
var s3FallbackMessage = new AmazonSQSTransportMessage(headers, "bucket address to resource");
entry = new SendMessageBatchRequestEntry(messageId, _serializer.Serialize(s3FallbackMessage));
}
else
{
entry = new SendMessageBatchRequestEntry(messageId, _serializer.Serialize(sqsMessage));
}
var delaySeconds = GetDelaySeconds(headers);
Expand Down Expand Up @@ -465,6 +480,13 @@ IAmazonSQS GetClientFromTransactionContext(ITransactionContext context)
TransportMessage ExtractTransportMessageFrom(Message message)
{
var sqsMessage = _serializer.Deserialize(message.Body);

if (sqsMessage.Headers.ContainsKey("rebus-sqs-s3-fallback"))
{
var messageBody = ""; // Download from S3
sqsMessage = new AmazonSQSTransportMessage(sqsMessage.Headers, messageBody);
}

return new TransportMessage(sqsMessage.Headers, GetBodyBytes(sqsMessage.Body));
}

Expand Down

0 comments on commit aadb7eb

Please sign in to comment.