本文整理汇总了Java中com.amazonaws.services.sns.model.CreateTopicRequest类的典型用法代码示例。如果您正苦于以下问题:Java CreateTopicRequest类的具体用法?Java CreateTopicRequest怎么用?Java CreateTopicRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CreateTopicRequest类属于com.amazonaws.services.sns.model包,在下文中一共展示了CreateTopicRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateListDeleteTopic_shouldCreateReturnAndDelete
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的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: testSetGetSubscriptionAttributes_shouldSetAndRespondSubscriptionAttributes
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的package包/类
@Test
public void testSetGetSubscriptionAttributes_shouldSetAndRespondSubscriptionAttributes() {
mockSns(new MockParameters());
// create topic and subscription
CreateTopicResult topicResult = sns.createTopic(new CreateTopicRequest().withName("important-topic"));
SubscribeResult subscribeResult = sns.subscribe(new SubscribeRequest().withTopicArn(topicResult.getTopicArn())
.withProtocol("sqs").withEndpoint("arn:aws:sqs:us-east-1:123456789012:queue1"));
// set subscription attribute
SetSubscriptionAttributesResult setAttrResult = sns.setSubscriptionAttributes(new SetSubscriptionAttributesRequest()
.withAttributeName("unicorns-exist").withAttributeValue("only in scotland").withSubscriptionArn(subscribeResult.getSubscriptionArn()));
assertNotNull("verify setting attributes result", setAttrResult);
// get subscription attribute
GetSubscriptionAttributesResult subAttributes = sns.getSubscriptionAttributes(new GetSubscriptionAttributesRequest()
.withSubscriptionArn(subscribeResult.getSubscriptionArn()));
assertEquals("verify subscription attribute","only in scotland",subAttributes.getAttributes().get("unicorns-exist"));
}
示例3: testPublish_shouldPublishTheMessage
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的package包/类
@Test
public void testPublish_shouldPublishTheMessage() {
CreateTopicResult topicResult = sns.createTopic(new CreateTopicRequest().withName("important-topic"));
PublishRequest publishReq = new PublishRequest()
.withMessage("{\"state\":\"liquid\",\"color\":\"black\",\"waking-up\":true}")
.withMessageStructure("json")
.withPhoneNumber("00121212")
.withSubject("eeffoc")
.withTopicArn(topicResult.getTopicArn());
PublishResult publishResult = sns.publish(publishReq);
assertNotNull("verify message id",publishResult.getMessageId());
Topic topic = getSnsTopics().get(topicResult.getTopicArn());
assertEquals("verify correct message count", 1, topic.getMessages().size());
assertEquals("verify message subject","eeffoc",topic.getMessages().get(0).getSubject());
assertEquals("verify message body","{\"state\":\"liquid\",\"color\":\"black\",\"waking-up\":true}",topic.getMessages().get(0).getBody());
assertEquals("verify message structure","json",topic.getMessages().get(0).getStructure());
}
示例4: resolveDestination
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的package包/类
@Override
public String resolveDestination(String name) throws DestinationResolutionException {
if (this.autoCreate) {
return this.amazonSns.createTopic(new CreateTopicRequest(name)).getTopicArn();
} else {
String physicalTopicName = name;
if (this.resourceIdResolver != null) {
physicalTopicName = this.resourceIdResolver.resolveToPhysicalResourceId(name);
}
if (physicalTopicName != null && AmazonResourceName.isValidAmazonResourceName(physicalTopicName)) {
return physicalTopicName;
}
String topicArn = getTopicResourceName(null, physicalTopicName);
if (topicArn == null) {
throw new IllegalArgumentException("No Topic with name: '" + name + "' found. Please use " +
"the right topic name or enable auto creation of topics for this DestinationResolver");
}
return topicArn;
}
}
示例5: resolveDestination_withAutoCreateEnabled_shouldCreateTopicDirectly
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的package包/类
@Test
public void resolveDestination_withAutoCreateEnabled_shouldCreateTopicDirectly() throws Exception {
// Arrange
String topicArn = "arn:aws:sns:eu-west:123456789012:test";
AmazonSNS sns = mock(AmazonSNS.class);
when(sns.createTopic(new CreateTopicRequest("test"))).thenReturn(new CreateTopicResult().withTopicArn(topicArn));
DynamicTopicDestinationResolver resolver = new DynamicTopicDestinationResolver(sns);
resolver.setAutoCreate(true);
// Act
String resolvedDestinationName = resolver.resolveDestination("test");
// Assert
assertEquals(topicArn, resolvedDestinationName);
}
示例6: createTopicIfNotExists
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的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);
}
}
示例7: postMessage
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的package包/类
/**
* Sends using the sns publisher
*/
@Override
public boolean postMessage(NotificationMessage nMsg,
BasicSubscriber subscriber) {
SNSSubscriber sub;
if (subscriber instanceof SNSSubscriber) {
sub = (SNSSubscriber) subscriber;
} else {
throw new ClassCastException("invalid subscriber " + subscriber.getClass().getName());
}
SNSMessage msg = buildSNSMessage(nMsg);
AmazonSNS sns = new AmazonSNSClient(new BasicAWSCredentials(sub.getAwsAccessKey(), sub.getAwsSecretKey()));
if (sub.getSnsEndpoint() != null) {
sns.setEndpoint(sub.getSnsEndpoint());
}
CreateTopicRequest tRequest = new CreateTopicRequest();
tRequest.setName(msg.getTopicName());
CreateTopicResult result = sns.createTopic(tRequest);
PublishRequest pr = new PublishRequest(result.getTopicArn(), msg.getTxtMessage()).withSubject(msg.getSubject());
try {
PublishResult pubresult = sns.publish(pr);
logger.info("Published msg with id - " + pubresult.getMessageId());
} catch (AmazonClientException ace) {
logger.error(ace.getMessage());
return false;
}
return true;
}
示例8: testGetSetTopicAttributes_shouldAddAndRespondAttributes
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的package包/类
@Test
public void testGetSetTopicAttributes_shouldAddAndRespondAttributes() {
mockSns(new MockParameters());
CreateTopicResult topicResult = sns.createTopic(new CreateTopicRequest().withName("attributefull-topic"));
SetTopicAttributesResult setAttrResult = sns.setTopicAttributes(topicResult.getTopicArn(), "planet", "Omega 3");
assertNotNull(setAttrResult);
GetTopicAttributesResult topicAttributes = sns.getTopicAttributes(new GetTopicAttributesRequest().withTopicArn(topicResult.getTopicArn()));
assertEquals("verify added attribute is correct", "Omega 3", topicAttributes.getAttributes().get("planet"));
sns.deleteTopic(topicResult.getTopicArn());
}
示例9: doStart
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的package包/类
@Override
public void doStart() throws Exception {
super.doStart();
snsClient = configuration.getAmazonSNSClient() != null
? configuration.getAmazonSNSClient() : createSNSClient();
// Override the setting Endpoint from url
if (ObjectHelper.isNotEmpty(configuration.getAmazonSNSEndpoint())) {
LOG.trace("Updating the SNS region with : {} " + configuration.getAmazonSNSEndpoint());
snsClient.setEndpoint(configuration.getAmazonSNSEndpoint());
}
if (configuration.getTopicArn() == null) {
// creates a new topic, or returns the URL of an existing one
CreateTopicRequest request = new CreateTopicRequest(configuration.getTopicName());
LOG.trace("Creating topic [{}] with request [{}]...", configuration.getTopicName(), request);
CreateTopicResult result = snsClient.createTopic(request);
configuration.setTopicArn(result.getTopicArn());
LOG.trace("Topic created with Amazon resource name: {}", configuration.getTopicArn());
}
if (ObjectHelper.isNotEmpty(configuration.getPolicy())) {
LOG.trace("Updating topic [{}] with policy [{}]", configuration.getTopicArn(), configuration.getPolicy());
snsClient.setTopicAttributes(new SetTopicAttributesRequest(configuration.getTopicArn(), "Policy", configuration.getPolicy()));
LOG.trace("Topic policy updated");
}
}
示例10: createTopic
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的package包/类
@Override
public Topic createTopic(CreateTopicRequest request,
ResultCapture<CreateTopicResult> extractor) {
ActionResult result = service.performAction("CreateTopic", request,
extractor);
if (result == null) return null;
return new TopicImpl(result.getResource());
}
示例11: createTopic
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的package包/类
@Override
public CreateTopicResult createTopic(CreateTopicRequest createTopicRequest) throws AmazonClientException {
String topicArn = BASE_ARN + createTopicRequest.getName();
CreateTopicResult result = new CreateTopicResult().withTopicArn(topicArn);
if (!_subscriptionsForTopic.containsKey(topicArn)) {
_subscriptionsForTopic.put(topicArn, new ArrayList<String>());
}
return result;
}
示例12: manualSubscriptionSetup
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的package包/类
public void manualSubscriptionSetup() {
final String queueName = someQueueName();
final String queueUrl = someNewQueue(queueName);
final String topicName = "manualSubscriptionSetup";
final String message = "hi from " + topicName;
AmazonSNS amazonSNS = new InMemorySNS(_amazonSQS1);
amazonSNS.createTopic(new CreateTopicRequest(topicName));
Assert.assertEquals(amazonSNS.listTopics().getTopics().size(), 1);
Assert.assertEquals(amazonSNS.listTopics().getTopics().get(0).getTopicArn(), makeTopicArn(topicName));
//make sure create is idempotent
amazonSNS.createTopic(new CreateTopicRequest(topicName));
Assert.assertEquals(amazonSNS.listTopics().getTopics().size(), 1, "existing topic duplicated?");
Assert.assertEquals(amazonSNS.listTopics().getTopics().get(0).getTopicArn(), makeTopicArn(topicName));
//subscribe.
amazonSNS.subscribe(new SubscribeRequest().
withEndpoint(getQueueArn(queueName)).
withProtocol("sqs").
withTopicArn(makeTopicArn(topicName)));
Assert.assertEquals(amazonSNS.listSubscriptions().getSubscriptions().size(), 1);
Assert.assertEquals(amazonSNS.listSubscriptions().getSubscriptions().get(0).getTopicArn(), makeTopicArn(topicName));
Assert.assertEquals(amazonSNS.
listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest(makeTopicArn(topicName)))
.getSubscriptions()
.size(),
1);
amazonSNS.publish(new PublishRequest(makeTopicArn(topicName), message));
ReceiveMessageResult result = _amazonSQS1.receiveMessage(new ReceiveMessageRequest(queueUrl));
Assert.assertEquals(result.getMessages().size(), 1);
Assert.assertEquals(result.getMessages().get(0).getBody(), message);
}
示例13: createTopic
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的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;
}
示例14: testCreateTopic_withNoRequestParams_shouldWork
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的package包/类
@Test
public void testCreateTopic_withNoRequestParams_shouldWork() {
mockSns(new MockParameters());
assertNotNull(sns.createTopic(new CreateTopicRequest()));
}
示例15: testSubscribeConfirmListUnsubscribe_shouldCreateVerifyListAndRemoveSubscription
import com.amazonaws.services.sns.model.CreateTopicRequest; //导入依赖的package包/类
@Test
public void testSubscribeConfirmListUnsubscribe_shouldCreateVerifyListAndRemoveSubscription() {
mockSns(new MockParameters());
// create topic
CreateTopicResult topicResult = sns.createTopic(new CreateTopicRequest().withName("important-topic"));
// subscribe to first topic
SubscribeResult subscribeResult = sns.subscribe(new SubscribeRequest().withTopicArn(topicResult.getTopicArn())
.withProtocol("sqs").withEndpoint("arn:aws:sqs:us-east-1:123456789012:queue1"));
assertNotNull("verify subscription ARN is created", subscribeResult.getSubscriptionArn());
// create second topic and subscribe to that one
CreateTopicResult secondTopicResult = sns.createTopic(new CreateTopicRequest().withName("someOther-topic"));
sns.subscribe(new SubscribeRequest().withTopicArn(secondTopicResult.getTopicArn())
.withProtocol("sqs").withEndpoint("arn:aws:sqs:us-east-1:564654654:queue7"));
// confirm first subscription
ConfirmSubscriptionResult confirmResultAuth = sns.confirmSubscription(new ConfirmSubscriptionRequest()
.withAuthenticateOnUnsubscribe("true").withToken("gold-token").withTopicArn(topicResult.getTopicArn()));
assertNotNull("verify auth confirmation with responded topic arn", confirmResultAuth.getSubscriptionArn());
ConfirmSubscriptionResult confirmResultNoAuth = sns.confirmSubscription(new ConfirmSubscriptionRequest()
.withAuthenticateOnUnsubscribe("false").withToken("gold-token").withTopicArn(topicResult.getTopicArn()));
assertNotNull("verify no auth confirmation with responded topic arn", confirmResultNoAuth.getSubscriptionArn());
// list all subscriptions
ListSubscriptionsResult allSubs = sns.listSubscriptions();
assertEquals("verify correct total subscription count", 2, allSubs.getSubscriptions().size());
com.amazonaws.services.sns.model.Subscription firstSub = allSubs.getSubscriptions().stream().filter(sub -> sub.getTopicArn().equals(topicResult.getTopicArn())).findFirst().get();
assertEquals("verify the correct subscription arn", subscribeResult.getSubscriptionArn(), firstSub.getSubscriptionArn());
assertEquals("verify the correct subscription topic", topicResult.getTopicArn(), firstSub.getTopicArn());
assertEquals("verify the correct subscription protocol", "sqs", firstSub.getProtocol());
assertEquals("verify the correct subscription endpoint", "arn:aws:sqs:us-east-1:123456789012:queue1", firstSub.getEndpoint());
assertNotNull("verify the correct subscription owner", firstSub.getOwner());
// list subscriptions of first topic
ListSubscriptionsByTopicResult topicsSubscriptions = sns.listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest(topicResult.getTopicArn()));
assertEquals("verify that the one subscription is contained in list", 1, topicsSubscriptions.getSubscriptions().size());
assertEquals("verify the correct subscription arn", subscribeResult.getSubscriptionArn(), topicsSubscriptions.getSubscriptions().get(0).getSubscriptionArn());
assertEquals("verify the correct subscription topic", topicResult.getTopicArn(), topicsSubscriptions.getSubscriptions().get(0).getTopicArn());
assertEquals("verify the correct subscription protocol", "sqs", topicsSubscriptions.getSubscriptions().get(0).getProtocol());
assertEquals("verify the correct subscription endpoint", "arn:aws:sqs:us-east-1:123456789012:queue1", topicsSubscriptions.getSubscriptions().get(0).getEndpoint());
assertNotNull("verify the correct subscription owner", topicsSubscriptions.getSubscriptions().get(0).getOwner());
// unsubscribe first topic
assertNotNull(sns.unsubscribe(subscribeResult.getSubscriptionArn()));
// check if really unsubscribed
ListSubscriptionsByTopicResult subsToFirstTopicAfterUnsubscribe = sns.listSubscriptionsByTopic(new ListSubscriptionsByTopicRequest(topicResult.getTopicArn()));
assertEquals("topic should be gone", 0, subsToFirstTopicAfterUnsubscribe.getSubscriptions().size());
// cleanup
sns.deleteTopic(topicResult.getTopicArn());
sns.deleteTopic(secondTopicResult.getTopicArn());
}