Java Code Examples for com.amazonaws.services.sns.model.Subscription#getSubscriptionArn()

The following examples show how to use com.amazonaws.services.sns.model.Subscription#getSubscriptionArn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SnsExecutor.java    From spring-integration-aws with MIT License 5 votes vote down vote up
private void processUrlSubscription(Subscription urlSubscription) {

		String snsUrlSubscriptionArn = null;
		for (Subscription subscription : client.listSubscriptions()
				.getSubscriptions()) {
			if (subscription.getTopicArn().equals(topicArn)
					&& subscription.getProtocol().equals(
							urlSubscription.getProtocol())
					&& subscription.getEndpoint().contains(
							urlSubscription.getEndpoint())) {
				if (!subscription.getSubscriptionArn().equals(
						"PendingConfirmation")) {
					snsUrlSubscriptionArn = subscription.getSubscriptionArn();
					break;
				}
			}
		}
		if (snsUrlSubscriptionArn == null) {

			SubscribeRequest request = new SubscribeRequest(topicArn,
					urlSubscription.getProtocol(),
					urlSubscription.getEndpoint());
			SubscribeResult result = client.subscribe(request);
			snsUrlSubscriptionArn = result.getSubscriptionArn();
			log.info("Subscribed URL to SNS with subscription ARN: "
					+ snsUrlSubscriptionArn);
		} else {
			log.info("Already subscribed with ARN: " + snsUrlSubscriptionArn);
		}
	}
 
Example 2
Source File: SnsExecutor.java    From spring-integration-aws with MIT License 4 votes vote down vote up
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);
	}
}