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


Java AmazonSNS类代码示例

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


AmazonSNS类属于com.amazonaws.services.sns包,在下文中一共展示了AmazonSNS类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
@Override
public void execute(PostDownloadExecution execution) {

    AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretAccessKey);

    AmazonSNS sns = snsClientBuilder.withRegion(region)
            .withCredentials(new AWSStaticCredentialsProvider(credentials)).build();

    LOGGER.debug("SNS: Topic Arn               : {}", arn);
    LOGGER.debug("SNS: Topic Region            : {}", region);
    LOGGER.debug("SNS: Topic Access Key        : {}", accessKey);
    LOGGER.debug("SNS: Topic Secret Access Key : {}", secretAccessKey);

    PublishRequest request = new PublishRequest();
    request.setTopicArn(arn);
    request.setMessageStructure("json");
    request.setMessage(formatJsonMessage(execution.fileName));
    request.setSubject("A new file has been downloaded");

    LOGGER.info("Publishing message to SNS");
    PublishResult result = sns.publish(request);
    LOGGER.info("Publish successful!");
    LOGGER.debug("{}", result.getMessageId());
}
 
开发者ID:linuxserver,项目名称:davos,代码行数:25,代码来源:SNSNotifyAction.java

示例2: testGetAmazonSNSClientCacheHitMiss

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
@Test
public void testGetAmazonSNSClientCacheHitMiss()
{
    // Create an AWS parameters DTO that contains proxy information.
    AwsParamsDto awsParamsDto = new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT);

    // Get an Amazon SNS client.
    AmazonSNS amazonSNS = awsClientFactory.getAmazonSNSClient(awsParamsDto);

    // Confirm a cache hit.
    assertEquals(amazonSNS,
        awsClientFactory.getAmazonSNSClient(new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST, HTTP_PROXY_PORT)));

    // Confirm a cache miss due to http proxy information.
    assertNotEquals(amazonSNS, awsClientFactory
        .getAmazonSNSClient(new AwsParamsDto(NO_AWS_ACCESS_KEY, NO_AWS_SECRET_KEY, NO_SESSION_TOKEN, HTTP_PROXY_HOST_2, HTTP_PROXY_PORT_2)));

    // Clear the cache.
    cacheManager.getCache(DaoSpringModuleConfig.HERD_CACHE_NAME).clear();

    // Confirm a cache miss due to cleared cache.
    assertNotEquals(amazonSNS, awsClientFactory.getAmazonSNSClient(awsParamsDto));
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:24,代码来源:AwsClientFactoryTest.java

示例3: retryVerifyPlatformApplication

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
private void retryVerifyPlatformApplication(AmazonSNS client) {
    int retry_count = 10000;
    while(true) {
        try {
            verifyPlatformApplication(this.client);
            break;
        } catch (Exception e) {
            retry_count--;
            System.out.println("Exception caught. message:" + e.getMessage());
            System.out.println(">>>>> retry count remaining: "+retry_count);
            if (retry_count == 0) {
                System.exit(BatchCreatePlatformEndpointSample.NOT_FOUND_ERROR_CODE);
            } else {
                try {
                    Thread.sleep(3000); 
                } catch (InterruptedException ee) {
                    System.exit(BatchCreatePlatformEndpointSample.NOT_FOUND_ERROR_CODE);
                }
                continue;
            }
        }
    }
}
 
开发者ID:tonchidot,项目名称:aws-java-sns-mobile-push-sample,代码行数:24,代码来源:CreateEndpointJob.java

示例4: postProcessBeanFactory

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    List<BeanDefinition> methodArgumentResolvers = new ManagedList<>(3);

    BeanDefinitionBuilder notificationMessageHandler = BeanDefinitionBuilder.rootBeanDefinition(NotificationMessageHandlerMethodArgumentResolver.class);
    methodArgumentResolvers.add(notificationMessageHandler.getBeanDefinition());

    BeanDefinitionBuilder notificationSubjectHandler = BeanDefinitionBuilder.rootBeanDefinition(NotificationSubjectHandlerMethodArgumentResolver.class);
    methodArgumentResolvers.add(notificationSubjectHandler.getBeanDefinition());

    BeanDefinitionBuilder notificationStatusBeanDefinition = BeanDefinitionBuilder.rootBeanDefinition(NotificationStatusHandlerMethodArgumentResolver.class);
    notificationStatusBeanDefinition.addConstructorArgReference(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonSNS.class.getName()));
    methodArgumentResolvers.add(notificationStatusBeanDefinition.getBeanDefinition());

    BeanDefinition requestMappingHandlerAdapter = beanFactory.getBeanDefinition("requestMappingHandlerAdapter");

    requestMappingHandlerAdapter.getPropertyValues().addPropertyValue("customArgumentResolvers", methodArgumentResolvers);
}
 
开发者ID:alainsahli,项目名称:spring-cloud-aws-reference-app,代码行数:19,代码来源:NotificationResolversConfiguration.java

示例5: sendPushMessage

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
public PublishResult sendPushMessage(AmazonSNS snsClient, PushPlatform platform, String targetArn, Map<String, Object> customAppMessageMap, Map<String, MessageAttributeValue> messageAttributes) throws IOException {
	Map<String, Object> appMessageMap = new HashMap<String, Object>();

	if (platform == PushPlatform.GCM) {
		appMessageMap.put("collapse_key", "single");
		appMessageMap.put("delay_while_idle", true);
		appMessageMap.put("time_to_live", 30);
		appMessageMap.put("dry_run", false);
	}

	if (customAppMessageMap != null) {
		appMessageMap.putAll(customAppMessageMap);
	}

	String message = ServerUtil.asJson(appMessageMap);

	return sendPushMessage(snsClient, platform, targetArn, message, messageAttributes);
}
 
开发者ID:GluuFederation,项目名称:oxAuth,代码行数:19,代码来源:PushSnsService.java

示例6: resolveDestination_withExistentTopic_returnsTopicArnFoundWhileListingTopic

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
@Test
public void resolveDestination_withExistentTopic_returnsTopicArnFoundWhileListingTopic() throws Exception {
    // Arrange
    String topicArn = "arn:aws:sns:eu-west:123456789012:test";

    AmazonSNS sns = mock(AmazonSNS.class);
    when(sns.listTopics(new ListTopicsRequest(null))).thenReturn(new ListTopicsResult().withTopics(new Topic().withTopicArn(topicArn)));

    DynamicTopicDestinationResolver resolver = new DynamicTopicDestinationResolver(sns);

    // Act
    String resolvedDestinationName = resolver.resolveDestination("test");

    // Assert
    assertEquals(topicArn, resolvedDestinationName);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:17,代码来源:DynamicTopicDestinationResolverTest.java

示例7: resolveDestination_withExistentTopicAndMarker_returnsTopicArnFoundWhileListingTopic

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
@Test
public void resolveDestination_withExistentTopicAndMarker_returnsTopicArnFoundWhileListingTopic() throws Exception {
    // Arrange

    AmazonSNS sns = mock(AmazonSNS.class);
    when(sns.listTopics(new ListTopicsRequest(null))).thenReturn(new ListTopicsResult().withNextToken("mark"));

    String topicArn = "arn:aws:sns:eu-west:123456789012:test";
    when(sns.listTopics(new ListTopicsRequest("mark"))).thenReturn(new ListTopicsResult().withTopics(new Topic().withTopicArn(topicArn)));

    DynamicTopicDestinationResolver resolver = new DynamicTopicDestinationResolver(sns);

    // Act
    String resolvedDestinationName = resolver.resolveDestination("test");

    // Assert
    assertEquals(topicArn, resolvedDestinationName);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:19,代码来源:DynamicTopicDestinationResolverTest.java

示例8: resolveDestination_withAutoCreateEnabled_shouldCreateTopicDirectly

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的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

示例9: resolveDestination_withResourceIdResolver_shouldCallIt

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
@Test
public void resolveDestination_withResourceIdResolver_shouldCallIt() throws Exception {
    // Arrange
    String physicalTopicName = "arn:aws:sns:eu-west:123456789012:myTopic";
    String logicalTopicName = "myTopic";

    ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
    when(resourceIdResolver.resolveToPhysicalResourceId(logicalTopicName)).thenReturn(physicalTopicName);

    AmazonSNS sns = mock(AmazonSNS.class);
    when(sns.listTopics(new ListTopicsRequest(null))).thenReturn(new ListTopicsResult().withTopics(new Topic().withTopicArn(physicalTopicName)));

    DynamicTopicDestinationResolver resolver = new DynamicTopicDestinationResolver(sns, resourceIdResolver);

    // Assert
    String resolvedDestinationName = resolver.resolveDestination(logicalTopicName);

    // Assert
    assertEquals(physicalTopicName, resolvedDestinationName);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:21,代码来源:DynamicTopicDestinationResolverTest.java

示例10: send_validTextMessage_usesTopicChannel

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
@Test
public void send_validTextMessage_usesTopicChannel() throws Exception {
    // Arrange
    AmazonSNS amazonSns = mock(AmazonSNS.class);
    NotificationMessagingTemplate notificationMessagingTemplate = new NotificationMessagingTemplate(amazonSns);
    String physicalTopicName = "arn:aws:sns:eu-west:123456789012:test";
    when(amazonSns.listTopics(new ListTopicsRequest(null))).thenReturn(new ListTopicsResult().withTopics(new Topic().withTopicArn(physicalTopicName)));
    notificationMessagingTemplate.setDefaultDestinationName(physicalTopicName);

    // Act
    notificationMessagingTemplate.send(MessageBuilder.withPayload("Message content").build());

    // Assert
    verify(amazonSns).publish(new PublishRequest(physicalTopicName,
            "Message content", null).withMessageAttributes(isNotNull()));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:17,代码来源:NotificationMessagingTemplateTest.java

示例11: sendMessage_validTextMessageAndSubject_returnsTrue

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
@Test
public void sendMessage_validTextMessageAndSubject_returnsTrue() throws Exception {
    // Arrange
    AmazonSNS amazonSns = mock(AmazonSNS.class);

    Message<String> stringMessage = MessageBuilder.withPayload("Message content").setHeader(TopicMessageChannel.NOTIFICATION_SUBJECT_HEADER, "Subject").build();
    MessageChannel messageChannel = new TopicMessageChannel(amazonSns, "topicArn");

    // Act
    boolean sent = messageChannel.send(stringMessage);

    // Assert
    verify(amazonSns, only()).publish(new PublishRequest("topicArn",
            "Message content", "Subject").withMessageAttributes(isNotNull()));
    assertTrue(sent);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:17,代码来源:TopicMessageChannelTest.java

示例12: sendMessage_validTextMessageWithoutSubject_returnsTrue

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
@Test
public void sendMessage_validTextMessageWithoutSubject_returnsTrue() throws Exception {
    // Arrange
    AmazonSNS amazonSns = mock(AmazonSNS.class);

    Message<String> stringMessage = MessageBuilder.withPayload("Message content").build();
    MessageChannel messageChannel = new TopicMessageChannel(amazonSns, "topicArn");

    // Act
    boolean sent = messageChannel.send(stringMessage);

    // Assert
    verify(amazonSns, only()).publish(new PublishRequest("topicArn",
            "Message content", null).withMessageAttributes(isNotNull()));
    assertTrue(sent);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:17,代码来源:TopicMessageChannelTest.java

示例13: sendMessage_validTextMessageAndTimeout_timeoutIsIgnored

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
@Test
public void sendMessage_validTextMessageAndTimeout_timeoutIsIgnored() throws Exception {
    // Arrange
    AmazonSNS amazonSns = mock(AmazonSNS.class);

    Message<String> stringMessage = MessageBuilder.withPayload("Message content").build();
    MessageChannel messageChannel = new TopicMessageChannel(amazonSns, "topicArn");

    // Act
    boolean sent = messageChannel.send(stringMessage, 10);

    // Assert
    verify(amazonSns, only()).publish(new PublishRequest("topicArn",
            "Message content", null).withMessageAttributes(isNotNull()));
    assertTrue(sent);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:17,代码来源:TopicMessageChannelTest.java

示例14: sendMessage_withStringMessageHeader_shouldBeSentAsTopicMessageAttribute

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
@Test
public void sendMessage_withStringMessageHeader_shouldBeSentAsTopicMessageAttribute() throws Exception {
    // Arrange
    AmazonSNS amazonSns = mock(AmazonSNS.class);
    ArgumentCaptor<PublishRequest> publishRequestArgumentCaptor = ArgumentCaptor.forClass(PublishRequest.class);
    when(amazonSns.publish(publishRequestArgumentCaptor.capture())).thenReturn(new PublishResult());

    String headerValue = "Header value";
    String headerName = "MyHeader";
    Message<String> message = MessageBuilder.withPayload("Hello").setHeader(headerName, headerValue).build();
    MessageChannel messageChannel = new TopicMessageChannel(amazonSns, "topicArn");

    // Act
    boolean sent = messageChannel.send(message);

    // Assert
    assertTrue(sent);
    assertEquals(headerValue, publishRequestArgumentCaptor.getValue().getMessageAttributes().get(headerName).getStringValue());
    assertEquals(MessageAttributeDataTypes.STRING, publishRequestArgumentCaptor.getValue().getMessageAttributes().get(headerName).getDataType());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:21,代码来源:TopicMessageChannelTest.java

示例15: sendMessage_withBinaryMessageHeader_shouldBeSentAsBinaryMessageAttribute

import com.amazonaws.services.sns.AmazonSNS; //导入依赖的package包/类
@Test
public void sendMessage_withBinaryMessageHeader_shouldBeSentAsBinaryMessageAttribute() throws Exception {
    // Arrange
    AmazonSNS amazonSns = mock(AmazonSNS.class);
    ArgumentCaptor<PublishRequest> publishRequestArgumentCaptor = ArgumentCaptor.forClass(PublishRequest.class);
    when(amazonSns.publish(publishRequestArgumentCaptor.capture())).thenReturn(new PublishResult());

    ByteBuffer headerValue = ByteBuffer.wrap("My binary data!".getBytes());
    String headerName = "MyHeader";
    Message<String> message = MessageBuilder.withPayload("Hello").setHeader(headerName, headerValue).build();
    MessageChannel messageChannel = new TopicMessageChannel(amazonSns, "topicArn");

    // Act
    boolean sent = messageChannel.send(message);

    // Assert
    assertTrue(sent);
    assertEquals(headerValue, publishRequestArgumentCaptor.getValue().getMessageAttributes().get(headerName).getBinaryValue());
    assertEquals(MessageAttributeDataTypes.BINARY, publishRequestArgumentCaptor.getValue().getMessageAttributes().get(headerName).getDataType());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-aws,代码行数:21,代码来源:TopicMessageChannelTest.java


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