Skip to content

Commit

Permalink
Added missing pagination to get all SNS topics. Added marking the mes…
Browse files Browse the repository at this point in the history
…sage as failed if topic not found. (#765)
  • Loading branch information
roman-bezmen committed Jan 14, 2021
1 parent 6383321 commit 83d623c
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/DotNetCore.CAP.AmazonSQS/ITransport.AmazonSQS.cs
Expand Up @@ -62,12 +62,15 @@ public async Task<OperateResult> SendAsync(TransportMessage message)
await _snsClient.PublishAsync(request);

_logger.LogDebug($"SNS topic message [{message.GetName().NormalizeForAws()}] has been published.");
return OperateResult.Success;
}
else

_logger.LogWarning($"Can't be found SNS topics for [{message.GetName().NormalizeForAws()}]");
return OperateResult.Failed(new OperateError
{
_logger.LogWarning($"Can't be found SNS topics for [{message.GetName().NormalizeForAws()}]");
}
return OperateResult.Success;
Code = "SNS",
Description = $"Can't be found SNS topics for [{message.GetName().NormalizeForAws()}]"
});
}
catch (Exception ex)
{
Expand Down Expand Up @@ -100,12 +103,21 @@ public async Task<bool> TryAddTopicArns()
if (_topicArnMaps == null)
{
_topicArnMaps = new Dictionary<string, string>();
var topics = await _snsClient.ListTopicsAsync();
topics.Topics.ForEach(x =>

string nextToken = null;
do
{
var name = x.TopicArn.Split(':').Last();
_topicArnMaps.Add(name, x.TopicArn);
});
var topics = nextToken == null
? await _snsClient.ListTopicsAsync()
: await _snsClient.ListTopicsAsync(nextToken);
topics.Topics.ForEach(x =>
{
var name = x.TopicArn.Split(':').Last();
_topicArnMaps.Add(name, x.TopicArn);
});
nextToken = topics.NextToken;
}
while (!string.IsNullOrEmpty(nextToken));

return true;
}
Expand Down

0 comments on commit 83d623c

Please sign in to comment.