private void processSqsSubscription(Subscription sqsSubscription) {
Assert.state(sqsExecutorMap != null,
"'sqsExecutorMap' must not be null");
SqsExecutor sqsExecutor = null;
String endpointValue = sqsSubscription.getEndpoint();
if (sqsExecutorMap.containsKey(endpointValue)) {
sqsExecutor = sqsExecutorMap.get(endpointValue);
sqsSubscription.setEndpoint(sqsExecutor.getQueueArn());
} else {
// endpointValue is the queue-arn
sqsSubscription.setEndpoint(endpointValue);
}
String snsSqsSubscriptionArn = null;
for (Subscription subscription : client.listSubscriptions()
.getSubscriptions()) {
if (subscription.getTopicArn().equals(topicArn)
&& subscription.getProtocol().equals(
sqsSubscription.getProtocol())
&& subscription.getEndpoint().equals(
sqsSubscription.getEndpoint())) {
snsSqsSubscriptionArn = subscription.getSubscriptionArn();
break;
}
}
if (snsSqsSubscriptionArn == null) {
SubscribeRequest request = new SubscribeRequest(topicArn,
sqsSubscription.getProtocol(),
sqsSubscription.getEndpoint());
SubscribeResult result = client.subscribe(request);
snsSqsSubscriptionArn = result.getSubscriptionArn();
log.info("Subscribed SQS to SNS with subscription ARN: "
+ snsSqsSubscriptionArn);
} else {
log.info("Already subscribed with ARN: " + snsSqsSubscriptionArn);
}
if (sqsExecutor != null) {
sqsExecutor.addSnsPublishPolicy(topicName, topicArn);
}
}