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

Commit

Permalink
Merge pull request #145 from manuel-sugawara/dr-146
Browse files Browse the repository at this point in the history
DR-146 Add queue name as attribute to each SQS message
  • Loading branch information
PeteE committed Sep 12, 2015
2 parents 23d462b + bc3d8cb commit 65e3f9a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/mindtouch.sqs/SqsClient.cs
Expand Up @@ -54,6 +54,7 @@ public class SqsClient : ISqsClient {
//--- Fields ---
private readonly AmazonSQSClient _client;
private readonly SqsClientConfig _config;
private readonly Dictionary<string, MessageAttributeValue> _defaultAttributes;
private const string RECEIVING_MESSAGE = "receiving message";
private const string DELETING_MESSAGE = "deleting message";
private const string SENDING_MESSAGE = "sending message";
Expand Down Expand Up @@ -87,6 +88,8 @@ public class SqsClient : ISqsClient {
} else {
_client = new AmazonSQSClient(new AmazonSQSConfig { ServiceURL = _config.Endpoint.ToString() });
}
var queueName = _config.Endpoint.LastSegment;
_defaultAttributes = new Dictionary<string, MessageAttributeValue> { { "QueueName", new MessageAttributeValue { StringValue = queueName } } };
}

//--- Methods ---
Expand Down Expand Up @@ -183,7 +186,8 @@ public class SqsClient : ISqsClient {
_client.SendMessage(new SendMessageRequest {
QueueUrl = GetQueueUrl(queueName.Value),
MessageBody = messageBody,
DelaySeconds = (int)delay.TotalSeconds
DelaySeconds = (int)delay.TotalSeconds,
MessageAttributes = _defaultAttributes
}),
queueName,
SENDING_MESSAGE);
Expand All @@ -201,7 +205,7 @@ public class SqsClient : ISqsClient {
throw new ArgumentException(string.Format("messageBodies is larger than {0}, which is the maximum", SqsUtils.MAX_NUMBER_OF_BATCH_SEND_MESSAGES));
}
var msgId = 1;
var sendEntries = (from messageBody in messageBodies select new SendMessageBatchRequestEntry { MessageBody = messageBody, Id = string.Format("msg-{0}", msgId++) }).ToList();
var sendEntries = (from messageBody in messageBodies select new SendMessageBatchRequestEntry { MessageBody = messageBody, Id = string.Format("msg-{0}", msgId++), MessageAttributes = _defaultAttributes }).ToList();
var response = Invoke(() =>
_client.SendMessageBatch(new SendMessageBatchRequest {
QueueUrl = GetQueueUrl(queueName.Value),
Expand Down

0 comments on commit 65e3f9a

Please sign in to comment.