本文整理汇总了Java中com.amazonaws.services.sns.model.CreateTopicResult.getTopicArn方法的典型用法代码示例。如果您正苦于以下问题:Java CreateTopicResult.getTopicArn方法的具体用法?Java CreateTopicResult.getTopicArn怎么用?Java CreateTopicResult.getTopicArn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.amazonaws.services.sns.model.CreateTopicResult
的用法示例。
在下文中一共展示了CreateTopicResult.getTopicArn方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateListDeleteTopic_shouldCreateReturnAndDelete
import com.amazonaws.services.sns.model.CreateTopicResult; //导入方法依赖的package包/类
@Test
public void testCreateListDeleteTopic_shouldCreateReturnAndDelete() {
mockSns(new MockParameters());
ListTopicsResult listTopicResultBefore = sns.listTopics();
assertEquals("topic list should contain zero items before insert",0,listTopicResultBefore.getTopics().size());
CreateTopicRequest create = new CreateTopicRequest()
.withName("major-topic");
CreateTopicResult createResult = sns.createTopic(create);
String topicArn = createResult.getTopicArn();
assertNotNull("verify returned topic ARN", topicArn);
ListTopicsResult listTopicResult = sns.listTopics();
assertEquals("after insert topic list should contain 1 item",1,listTopicResult.getTopics().size());
assertEquals("after insert topic list should contain before inserted topic arn", topicArn,
listTopicResult.getTopics().get(0).getTopicArn());
DeleteTopicResult deleteResult = sns.deleteTopic(topicArn);
assertNotNull(deleteResult);
ListTopicsResult listTopicsAfterDeletion = sns.listTopics();
assertEquals("topic list should contain zero items after deletion",0,listTopicsAfterDeletion.getTopics().size());
}
示例2: getOrCreateNotification
import com.amazonaws.services.sns.model.CreateTopicResult; //导入方法依赖的package包/类
/**
*
* @param email
* @return
*/
public String getOrCreateNotification(String email) {
String ret = null;
String topicName = getTopicName(email);
String nextToken = null;
do {
ListTopicsResult listTopics = asyncSnsClient.listTopics(nextToken);
List<Topic> topics = listTopics.getTopics();
for (Topic s : topics) {
if (s.getTopicArn().endsWith(topicName)) {
ret = s.getTopicArn();
break;
}
}
nextToken = listTopics.getNextToken();
} while (ret == null && nextToken != null);
if (ret == null) {
// create the topic and the subscription
CreateTopicResult topic = asyncSnsClient.createTopic(topicName);
SubscribeRequest req = new SubscribeRequest(topic.getTopicArn(), "email", email);
asyncSnsClient.subscribeAsync(req);
ret = topic.getTopicArn();
}
return ret;
}
示例3: main
import com.amazonaws.services.sns.model.CreateTopicResult; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
final AmazonSNSClient client = Region.getRegion(Regions.EU_CENTRAL_1).createClient(AmazonSNSClient.class, null,
null);
CreateTopicResult createTopic = client.createTopic("facilities");
createTopic.getTopicArn();
SubscribeResult subscribe = client.subscribe(createTopic.getTopicArn(), "email", "[email protected]");
final PublishRequest publishRequest = new PublishRequest(createTopic.getTopicArn(), "Test message");
client.publish(publishRequest);
}
示例4: createTopicIfNotExists
import com.amazonaws.services.sns.model.CreateTopicResult; //导入方法依赖的package包/类
private void createTopicIfNotExists() {
for (Topic topic : client.listTopics().getTopics()) {
if (topic.getTopicArn().contains(topicName)) {
topicArn = topic.getTopicArn();
break;
}
}
if (topicArn == null) {
CreateTopicRequest request = new CreateTopicRequest(topicName);
CreateTopicResult result = client.createTopic(request);
topicArn = result.getTopicArn();
log.debug("Topic created, arn: " + topicArn);
} else {
log.debug("Topic already created: " + topicArn);
}
}
示例5: createTopic
import com.amazonaws.services.sns.model.CreateTopicResult; //导入方法依赖的package包/类
/**
* Creates a SNS topic.
*
* @param topic string
* @param email address to be notified when there is any event for this topic.
* @return false if there is any error.
* @throws Exception
*/
public boolean createTopic(final String topic, final String email)
throws Exception{
CreateTopicRequest request = new CreateTopicRequest()
.withName(topic);
CreateTopicResult result = null;
try {
result = snsClient.createTopic(request);
} catch (Exception e) {
LGR.setUseParentHandlers(true);
LGR.log(Level.SEVERE, null, e);
LGR.setUseParentHandlers(false);
return false;
}
topicARN = result.getTopicArn();
LGR.log(Level.INFO, "topic arn is {0}", topicARN);
SubscribeRequest request2 = new SubscribeRequest()
.withTopicArn(topicARN).withEndpoint(email).withProtocol("email");
SubscribeResult result2 = snsClient.subscribe(request2);
LGR.log(Level.INFO, "subscription ARN {0}",
result2.getSubscriptionArn());
return true;
}
示例6: shouldFindSNSTopicIfPresent
import com.amazonaws.services.sns.model.CreateTopicResult; //导入方法依赖的package包/类
@Test
public void shouldFindSNSTopicIfPresent() {
CreateTopicResult createResult = snsClient.createTopic(SNSNotificationSender.TOPIC_NAME);
String arn = createResult.getTopicArn();
assertFalse(sender.getTopicARN().isEmpty());
snsClient.deleteTopic(arn);
SNSNotificationSender senderB = new SNSNotificationSender(snsClient);
assertTrue(senderB.getTopicARN().isEmpty());
}
示例7: createTopic
import com.amazonaws.services.sns.model.CreateTopicResult; //导入方法依赖的package包/类
private String createTopic(String arn) {
CreateTopicResult result
= snsClient.createTopic(new CreateTopicRequest(arn));
return result.getTopicArn();
}
示例8: createNotificationTopicIfNotExist
import com.amazonaws.services.sns.model.CreateTopicResult; //导入方法依赖的package包/类
public String createNotificationTopicIfNotExist(String topicName){
CreateTopicRequest createTopicRequest = new CreateTopicRequest(topicName);
CreateTopicResult createTopicResult = snsClient.createTopic(createTopicRequest);
return createTopicResult.getTopicArn();
}
示例9: shouldSendNotificationMessageOnTopic
import com.amazonaws.services.sns.model.CreateTopicResult; //导入方法依赖的package包/类
@Test
public void shouldSendNotificationMessageOnTopic() throws CfnAssistException, MissingArgumentException, InterruptedException, IOException {
User user = new User("path", "userName", "userId", "userArn", new Date());
CFNAssistNotification notification = new CFNAssistNotification("name", "complete", user);
CreateTopicResult createResult = snsClient.createTopic(SNSNotificationSender.TOPIC_NAME);
String SNSarn = createResult.getTopicArn();
assertNotNull(SNSarn);
// test the SNS notification by creating a SQS and subscribing that to the SNS
CreateQueueResult queueResult = createQueue();
String queueUrl = queueResult.getQueueUrl();
// give queue perms to subscribe to SNS
Map<String, String> attribrutes = policyManager.getQueueAttributes(queueUrl);
String queueArn = attribrutes.get(QueuePolicyManager.QUEUE_ARN_KEY);
policyManager.checkOrCreateQueuePermissions(attribrutes, SNSarn, queueArn, queueUrl);
// create subscription
SubscribeRequest subscribeRequest = new SubscribeRequest(SNSarn, SNSEventSource.SQS_PROTO, queueArn);
SubscribeResult subResult = snsClient.subscribe(subscribeRequest);
String subscriptionArn = subResult.getSubscriptionArn();
// send SNS and then check right thing arrives at SQS
sender.sendNotification(notification);
ReceiveMessageRequest request = new ReceiveMessageRequest().
withQueueUrl(queueUrl).
withWaitTimeSeconds(10);
ReceiveMessageResult receiveResult = sqsClient.receiveMessage(request);
List<Message> messages = receiveResult.getMessages();
sqsClient.deleteQueue(queueUrl);
snsClient.unsubscribe(subscriptionArn);
snsClient.deleteTopic(SNSarn);
assertEquals(1, messages.size());
Message msg = messages.get(0);
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(msg.getBody());
JsonNode messageNode = rootNode.get("Message");
String json = messageNode.textValue();
CFNAssistNotification result = CFNAssistNotification.fromJSON(json);
assertEquals(notification, result);
}
示例10: getTopicArn
import com.amazonaws.services.sns.model.CreateTopicResult; //导入方法依赖的package包/类
public static String getTopicArn( final AmazonSNSClient sns, final String queueName, final boolean createOnMissing )
throws Exception {
if ( logger.isTraceEnabled() ) {
logger.trace( "Looking up Topic ARN: {}", queueName );
}
ListTopicsResult listTopicsResult = sns.listTopics();
String topicArn = null;
for ( Topic topic : listTopicsResult.getTopics() ) {
String arn = topic.getTopicArn();
if ( queueName.equals( arn.substring( arn.lastIndexOf( ':' ) ) ) ) {
topicArn = arn;
if (logger.isTraceEnabled()) {
logger.trace( "Found existing topic arn=[{}] for queue=[{}]", topicArn, queueName );
}
}
}
if ( topicArn == null && createOnMissing ) {
if (logger.isTraceEnabled()) {
logger.trace("Creating topic for queue=[{}]...", queueName);
}
CreateTopicResult createTopicResult = sns.createTopic( queueName );
topicArn = createTopicResult.getTopicArn();
if (logger.isTraceEnabled()) {
logger.trace("Successfully created topic with name {} and arn {}", queueName, topicArn);
}
}
else {
logger.error( "Error looking up topic ARN for queue=[{}] and createOnMissing=[{}]", queueName,
createOnMissing );
}
if ( logger.isTraceEnabled() ) {
logger.trace( "Returning Topic ARN=[{}] for Queue=[{}]", topicArn, queueName );
}
return topicArn;
}
示例11: process
import com.amazonaws.services.sns.model.CreateTopicResult; //导入方法依赖的package包/类
public void process(Exchange exchange) throws Exception {
// TODO cache arns and don't create if not necessary
final String topic = determineTopic(exchange);
// creates a new topic, or returns the URL of an existing one
CreateTopicRequest request = new CreateTopicRequest(topic);
LOG.trace("Creating topic [{}] with request [{}]...", topic, request);
final AmazonSNS snsClient = getEndpoint().getSNSClient();
CreateTopicResult result = snsClient.createTopic(request);
final String topicArn = result.getTopicArn();
LOG.trace("Topic created with Amazon resource name: {}", topicArn);
final SnsConfiguration configuration = getEndpoint().getConfiguration();
if (ObjectHelper.isNotEmpty(configuration.getPolicy())) {
LOG.trace("Updating topic [{}] with policy [{}]", topicArn, configuration.getPolicy());
snsClient.setTopicAttributes(
new SetTopicAttributesRequest(topicArn, "Policy", configuration.getPolicy()));
LOG.trace("Topic policy updated");
}
PublishRequest publishRequest = new PublishRequest();
publishRequest.setTopicArn(topicArn);
publishRequest.setSubject(determineSubject(exchange));
publishRequest.setMessageStructure(determineMessageStructure(exchange));
publishRequest.setMessage(exchange.getIn().getBody(String.class));
LOG.trace("Sending request [{}] from exchange [{}]...", publishRequest, exchange);
PublishResult publishResult = snsClient.publish(publishRequest);
LOG.trace("Received result [{}]", publishResult);
Message message = getMessageForResponse(exchange);
message.setHeader(SnsConstants.MESSAGE_ID, publishResult.getMessageId());
}