SendMessageBatchRequestEntry GetBatchRequestEntry(OutgoingMessage message) { var transportMessage = message.TransportMessage; var headers = transportMessage.Headers; var messageId = headers[Headers.MessageId]; var sqsMessage = new AmazonSQSTransportMessage(transportMessage.Headers, GetBody(transportMessage.Body)); var entry = new SendMessageBatchRequestEntry(messageId, _serializer.Serialize(sqsMessage)); var delaySeconds = GetDelaySeconds(headers); if (delaySeconds != null) { entry.DelaySeconds = delaySeconds.Value; } if (message.DestinationAddress.EndsWith(".fifo")) { if (headers.ContainsKey(MessageGroupIdHeader)) { entry.MessageGroupId = headers[MessageGroupIdHeader]; } if (headers.ContainsKey(MessageDeduplicationIdHeader)) { entry.MessageDeduplicationId = headers[MessageDeduplicationIdHeader]; } } return(entry); }
async Task SendOutgoingMessages(ConcurrentQueue <OutgoingMessage> outgoingMessages, ITransactionContext context) { if (!outgoingMessages.Any()) { return; } var client = GetClientFromTransactionContext(context); var messagesByDestination = outgoingMessages .GroupBy(m => m.DestinationAddress) .ToList(); await Task.WhenAll( messagesByDestination .Select(async batch => { var entries = batch .Select(message => { var transportMessage = message.TransportMessage; var headers = transportMessage.Headers; var messageId = headers[Headers.MessageId]; var sqsMessage = new AmazonSQSTransportMessage(transportMessage.Headers, GetBody(transportMessage.Body)); var entry = new SendMessageBatchRequestEntry(messageId, _serializer.Serialize(sqsMessage)); var delaySeconds = GetDelaySeconds(headers); if (delaySeconds != null) { entry.DelaySeconds = delaySeconds.Value; } return(entry); }) .ToList(); var destinationUrl = GetDestinationQueueUrlByName(batch.Key, context); foreach (var batchToSend in entries.Batch(10)) { var request = new SendMessageBatchRequest(destinationUrl, batchToSend); var response = await client.SendMessageBatchAsync(request); if (response.Failed.Any()) { var failed = response.Failed .Select(f => new AmazonSQSException($"Failed {f.Message} with Id={f.Id}, Code={f.Code}, SenderFault={f.SenderFault}")); throw new AggregateException(failed); } } }) ); }
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))); }
public string Serialize(AmazonSQSTransportMessage message) { return(JsonConvert.SerializeObject(message)); }