当前位置: 首页>>代码示例>>Java>>正文


Java CreateTopicResult类代码示例

本文整理汇总了Java中com.amazonaws.services.sns.model.CreateTopicResult的典型用法代码示例。如果您正苦于以下问题:Java CreateTopicResult类的具体用法?Java CreateTopicResult怎么用?Java CreateTopicResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CreateTopicResult类属于com.amazonaws.services.sns.model包,在下文中一共展示了CreateTopicResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:25,代码来源:MockSnsTest.java

示例2: testSetGetSubscriptionAttributes_shouldSetAndRespondSubscriptionAttributes

import com.amazonaws.services.sns.model.CreateTopicResult; //导入依赖的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"));
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:17,代码来源:MockSnsTest.java

示例3: testPublish_shouldPublishTheMessage

import com.amazonaws.services.sns.model.CreateTopicResult; //导入依赖的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());
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:21,代码来源:MockSnsTest.java

示例4: 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;
}
 
开发者ID:intuit,项目名称:Tank,代码行数:31,代码来源:CloudwatchInstance.java

示例5: 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);
	}
 
开发者ID:highsource,项目名称:aufzugswaechter,代码行数:11,代码来源:HelloWorldSNS.java

示例6: resolveDestination_withAutoCreateEnabled_shouldCreateTopicDirectly

import com.amazonaws.services.sns.model.CreateTopicResult; //导入依赖的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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:18,代码来源:DynamicTopicDestinationResolverTest.java

示例7: 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);
	}
}
 
开发者ID:3pillarlabs,项目名称:spring-integration-aws,代码行数:17,代码来源:SnsExecutor.java

示例8: testExceptionInInitializer

import com.amazonaws.services.sns.model.CreateTopicResult; //导入依赖的package包/类
@Test
public void testExceptionInInitializer() throws Exception
{
    initialize("TestSNSAppender/testWriterOperationByName.properties");

    MockSNSClient mockClient = new MockSNSClient("example", Arrays.asList("argle", "bargle"))
    {
        @Override
        protected CreateTopicResult createTopic(String name)
        {
            throw new TestingException("arbitrary failure");
        }
    };

    appender.setWriterFactory(mockClient.newWriterFactory());
    appender.setThreadFactory(new DefaultThreadFactory());

    // first message triggers writer creation

    logger.info("message one");
    waitForInitialization();

    AbstractLogWriter writer = (AbstractLogWriter)appender.getWriter();
    MessageQueue messageQueue = appender.getMessageQueue();

    assertTrue("initialization message was non-blank",  ! writer.getInitializationMessage().equals(""));
    assertEquals("initialization exception retained",   TestingException.class,     writer.getInitializationException().getClass());
    assertEquals("message queue set to discard all",    0,                          messageQueue.getDiscardThreshold());
    assertEquals("message queue set to discard all",    DiscardAction.oldest,       messageQueue.getDiscardAction());
    assertEquals("messages in queue (initial)",         1,                          messageQueue.toList().size());

    // trying to log another message should clear the queue

    logger.info("message two");
    assertEquals("messages in queue (second try)",      0,                          messageQueue.toList().size());
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:37,代码来源:TestSNSAppender.java

示例9: postMessage

import com.amazonaws.services.sns.model.CreateTopicResult; //导入依赖的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;
}
 
开发者ID:oneops,项目名称:oneops,代码行数:36,代码来源:SNSService.java

示例10: testGetSetTopicAttributes_shouldAddAndRespondAttributes

import com.amazonaws.services.sns.model.CreateTopicResult; //导入依赖的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());
}
 
开发者ID:daflockinger,项目名称:unitstack,代码行数:15,代码来源:MockSnsTest.java

示例11: createTopicSupplier

import com.amazonaws.services.sns.model.CreateTopicResult; //导入依赖的package包/类
private Supplier<String> createTopicSupplier(final String topicName) {
    return Suppliers.memoize(new Supplier<String>() {
        @Override
        public String get() {
            // This will create the topic if it doesn't exist or return the existing topic if it does.
            CreateTopicResult topic = _amazonSNS.createTopic(topicName);
            return topic.getTopicArn();
        }
    });
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:11,代码来源:SNSStashStateListener.java

示例12: subscribeForFacility

import com.amazonaws.services.sns.model.CreateTopicResult; //导入依赖的package包/类
@Override
public void subscribeForFacility(Long equipmentnumber, String email) {
	Validate.notNull(equipmentnumber);
	final Facility facility = getFacilityService().findByEquipmentnumber(equipmentnumber);
	if (facility != null) {
		String topicName = MessageFormat.format(FACILITY_TOPIC_NAME_PATTERN, equipmentnumber);
		CreateTopicResult topicResult = getClient().createTopic(topicName);
		getClient().subscribe(new SubscribeRequest(topicResult.getTopicArn(), EMAIL_PROTOCOL, email));
	}
}
 
开发者ID:highsource,项目名称:aufzugswaechter,代码行数:11,代码来源:AmazonSNSFacilityStateChangedEventEmailSubscriptionService.java

示例13: doStart

import com.amazonaws.services.sns.model.CreateTopicResult; //导入依赖的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");
    }
    
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:34,代码来源:SnsEndpoint.java

示例14: createTopic

import com.amazonaws.services.sns.model.CreateTopicResult; //导入依赖的package包/类
@Test
public void createTopic() {
    CreateTopicResult result = mock(CreateTopicResult.class);
    when(sns.createTopic(anyString())).thenReturn(result);

    assertThat(service.createTopic(TOPIC_NAME)).isEqualTo(result);
    verify(sns).createTopic(TOPIC_NAME);
}
 
开发者ID:OpenG,项目名称:aws-java-sdk,代码行数:9,代码来源:SNSServiceTest.java

示例15: createTopic

import com.amazonaws.services.sns.model.CreateTopicResult; //导入依赖的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());
}
 
开发者ID:awslabs,项目名称:aws-sdk-java-resources,代码行数:11,代码来源:SNSImpl.java


注:本文中的com.amazonaws.services.sns.model.CreateTopicResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。