com.amazonaws.services.sns.AmazonSNS Java Examples
The following examples show how to use
com.amazonaws.services.sns.AmazonSNS.
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: SQSSubscriber.java From echo with Apache License 2.0 | 6 votes |
public SQSSubscriber( ObjectMapper objectMapper, AmazonPubsubProperties.AmazonPubsubSubscription subscription, PubsubMessageHandler pubsubMessageHandler, AmazonSNS amazonSNS, AmazonSQS amazonSQS, Supplier<Boolean> isEnabled, Registry registry) { this.objectMapper = objectMapper; this.subscription = subscription; this.pubsubMessageHandler = pubsubMessageHandler; this.amazonSNS = amazonSNS; this.amazonSQS = amazonSQS; this.isEnabled = isEnabled; this.registry = registry; this.queueARN = new ARN(subscription.getQueueARN()); this.topicARN = new ARN(subscription.getTopicARN()); }
Example #2
Source File: DynamicTopicDestinationResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test 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 assertThat(resolvedDestinationName).isEqualTo(topicArn); }
Example #3
Source File: DynamicTopicDestinationResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test 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 assertThat(resolvedDestinationName).isEqualTo(topicArn); }
Example #4
Source File: DynamicTopicDestinationResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test 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 assertThat(resolvedDestinationName).isEqualTo(physicalTopicName); }
Example #5
Source File: NotificationMessagingTemplateTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test 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())); }
Example #6
Source File: NotificationMessagingTemplateTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void send_validTextMessageWithCustomDestinationResolver_usesTopicChannel() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); NotificationMessagingTemplate notificationMessagingTemplate = new NotificationMessagingTemplate( amazonSns, (DestinationResolver<String>) name -> name.toUpperCase(Locale.ENGLISH), null); // Act notificationMessagingTemplate.send("test", MessageBuilder.withPayload("Message content").build()); // Assert verify(amazonSns).publish(new PublishRequest("TEST", "Message content", null) .withMessageAttributes(isNotNull())); }
Example #7
Source File: TopicMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test 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())); assertThat(sent).isTrue(); }
Example #8
Source File: TopicMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test 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())); assertThat(sent).isTrue(); }
Example #9
Source File: DynamicTopicDestinationResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void resolveDestination_withNonExistentTopicAndWithMarkerReturnedOnListTopics_shouldCallListMultipleTimeWithMarkerAndThrowIllegalArgumentException() // @checkstyle:on throws Exception { // Arrange AmazonSNS sns = mock(AmazonSNS.class); when(sns.listTopics(new ListTopicsRequest(null))) .thenReturn(new ListTopicsResult().withNextToken("foo")); when(sns.listTopics(new ListTopicsRequest("foo"))) .thenReturn(new ListTopicsResult()); DynamicTopicDestinationResolver resolver = new DynamicTopicDestinationResolver( sns); // Assert assertThatThrownBy(() -> resolver.resolveDestination("test")) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("No topic found for name :'test'"); }
Example #10
Source File: SNSNotificationsConfig.java From metacat with Apache License 2.0 | 6 votes |
/** * SNS Notification Publisher. * * @param amazonSNS The SNS client to use * @param config The system configuration abstraction to use * @param objectMapper The object mapper to use * @param snsNotificationMetric The sns notification metric * @param snsNotificationServiceUtil The SNS notification util * @return Configured Notification Service bean */ @Bean public SNSNotificationServiceImpl snsNotificationService( final AmazonSNS amazonSNS, final Config config, final ObjectMapper objectMapper, final SNSNotificationMetric snsNotificationMetric, final SNSNotificationServiceUtil snsNotificationServiceUtil ) { final String tableArn = config.getSnsTopicTableArn(); if (StringUtils.isEmpty(tableArn)) { throw new IllegalStateException( "SNS Notifications are enabled but no table ARN provided. Unable to configure." ); } final String partitionArn = config.getSnsTopicPartitionArn(); if (StringUtils.isEmpty(partitionArn)) { throw new IllegalStateException( "SNS Notifications are enabled but no partition ARN provided. Unable to configure." ); } log.info("SNS notifications are enabled. Creating SNSNotificationServiceImpl bean."); return new SNSNotificationServiceImpl(amazonSNS, tableArn, partitionArn, objectMapper, config, snsNotificationMetric, snsNotificationServiceUtil); }
Example #11
Source File: SNSNotificationServiceImpl.java From metacat with Apache License 2.0 | 6 votes |
/** * Constructor. * * @param client The SNS client to use to publish notifications * @param tableTopicArn The topic to publish table related notifications to * @param partitionTopicArn The topic to publish partition related notifications to * @param mapper The object mapper to use to convert objects to JSON strings * @param config The system config * @param notificationMetric The SNS notification metric * @param snsNotificationServiceUtil The SNS notification service util */ public SNSNotificationServiceImpl( final AmazonSNS client, @Size(min = 1) final String tableTopicArn, @Size(min = 1) final String partitionTopicArn, final ObjectMapper mapper, final Config config, final SNSNotificationMetric notificationMetric, final SNSNotificationServiceUtil snsNotificationServiceUtil ) { this.client = client; this.tableTopicArn = tableTopicArn; this.partitionTopicArn = partitionTopicArn; this.mapper = mapper; this.config = config; this.notificationMetric = notificationMetric; this.snsNotificationServiceUtil = snsNotificationServiceUtil; }
Example #12
Source File: PushSnsService.java From oxAuth with MIT License | 6 votes |
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); }
Example #13
Source File: AWSClientUtils.java From camel-kafka-connector with Apache License 2.0 | 6 votes |
public static AmazonSNS newSNSClient() { LOG.debug("Creating a custom SNS client for running a AWS SNS test"); AmazonSNSClientBuilder clientBuilder = AmazonSNSClientBuilder .standard(); String awsInstanceType = System.getProperty("aws-service.instance.type"); String region = getRegion(); if (awsInstanceType == null || awsInstanceType.equals("local-aws-container")) { String amazonHost = System.getProperty(AWSConfigs.AMAZON_AWS_HOST); ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.setProtocol(Protocol.HTTP); clientBuilder .withClientConfiguration(clientConfiguration) .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(amazonHost, region)) .withCredentials(new TestAWSCredentialsProvider("accesskey", "secretkey")); } else { clientBuilder .withRegion(region) .withCredentials(new TestAWSCredentialsProvider()); } return clientBuilder.build(); }
Example #14
Source File: AwsClientFactoryTest.java From herd with Apache License 2.0 | 6 votes |
@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, AWS_REGION_NAME_US_EAST_1); // 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, AWS_REGION_NAME_US_EAST_1))); // 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, AWS_REGION_NAME_US_EAST_1))); // Clear the cache. cacheManager.getCache(DaoSpringModuleConfig.HERD_CACHE_NAME).clear(); // Confirm a cache miss due to cleared cache. assertNotEquals(amazonSNS, awsClientFactory.getAmazonSNSClient(awsParamsDto)); }
Example #15
Source File: TemporarySQSQueue.java From front50 with Apache License 2.0 | 6 votes |
private String getSnsTopicArn(AmazonSNS amazonSNS, String topicName) { ListTopicsResult listTopicsResult = amazonSNS.listTopics(); String nextToken = listTopicsResult.getNextToken(); List<Topic> topics = listTopicsResult.getTopics(); while (nextToken != null) { listTopicsResult = amazonSNS.listTopics(nextToken); nextToken = listTopicsResult.getNextToken(); topics.addAll(listTopicsResult.getTopics()); } return topics.stream() .filter(t -> t.getTopicArn().toLowerCase().endsWith(":" + topicName.toLowerCase())) .map(Topic::getTopicArn) .findFirst() .orElseThrow( () -> new IllegalArgumentException("No SNS topic found (topicName: " + topicName + ")")); }
Example #16
Source File: SQSSubscriber.java From kork with Apache License 2.0 | 6 votes |
public SQSSubscriber( AmazonPubsubProperties.AmazonPubsubSubscription subscription, AmazonPubsubMessageHandler messageHandler, AmazonMessageAcknowledger messageAcknowledger, AmazonSNS amazonSNS, AmazonSQS amazonSQS, Supplier<Boolean> isEnabled, Registry registry) { this.subscription = subscription; this.messageHandler = messageHandler; this.messageAcknowledger = messageAcknowledger; this.amazonSNS = amazonSNS; this.amazonSQS = amazonSQS; this.isEnabled = isEnabled; this.registry = registry; this.queueARN = new ARN(subscription.getQueueARN()); this.topicARN = new ARN(subscription.getTopicARN()); }
Example #17
Source File: NotificationStatusHandlerMethodArgumentResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void resolveArgument_wrongMessageType_reportsErrors() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); NotificationStatusHandlerMethodArgumentResolver resolver = new NotificationStatusHandlerMethodArgumentResolver( amazonSns); byte[] subscriptionRequestJsonContent = FileCopyUtils.copyToByteArray( new ClassPathResource("notificationMessage.json", getClass()) .getInputStream()); MockHttpServletRequest servletRequest = new MockHttpServletRequest(); servletRequest.setContent(subscriptionRequestJsonContent); MethodParameter methodParameter = new MethodParameter( ReflectionUtils.findMethod(NotificationMethods.class, "subscriptionMethod", NotificationStatus.class), 0); // Assert assertThatThrownBy(() -> resolver.resolveArgument(methodParameter, null, new ServletWebRequest(servletRequest), null)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("NotificationStatus is only available"); }
Example #18
Source File: SnsIOTest.java From beam with Apache License 2.0 | 6 votes |
@Test public void testCustomCoder() throws Exception { final PublishRequest request1 = createSampleMessage("my_first_message"); final TupleTag<PublishResult> results = new TupleTag<>(); final AmazonSNS amazonSnsSuccess = getAmazonSnsMockSuccess(); final MockCoder mockCoder = new MockCoder(); final PCollectionTuple snsWrites = p.apply(Create.of(request1)) .apply( SnsIO.write() .withTopicName(topicName) .withAWSClientsProvider(new Provider(amazonSnsSuccess)) .withResultOutputTag(results) .withCoder(mockCoder)); final PCollection<Long> publishedResultsSize = snsWrites .get(results) .apply(MapElements.into(TypeDescriptors.strings()).via(result -> result.getMessageId())) .apply(Count.globally()); PAssert.that(publishedResultsSize).containsInAnyOrder(ImmutableList.of(1L)); p.run().waitUntilFinish(); assertThat(mockCoder.captured).isNotNull(); }
Example #19
Source File: NotificationsAutoConfiguration.java From genie with Apache License 2.0 | 6 votes |
/** * Create a {@link JobFinishedSNSPublisher} unless one exists in the context already. * * @param properties configuration properties * @param registry the metrics registry * @param snsClient the Amazon SNS client * @param dataServices The {@link DataServices} instance to use * @return a {@link JobFinishedSNSPublisher} */ @Bean @ConditionalOnProperty(value = SNSNotificationsProperties.ENABLED_PROPERTY, havingValue = "true") @ConditionalOnMissingBean(JobFinishedSNSPublisher.class) public JobFinishedSNSPublisher jobFinishedSNSPublisher( final SNSNotificationsProperties properties, final MeterRegistry registry, final AmazonSNS snsClient, final DataServices dataServices ) { return new JobFinishedSNSPublisher( snsClient, properties, dataServices, registry, GenieObjectMapper.getMapper() ); }
Example #20
Source File: SnsIOTest.java From beam with Apache License 2.0 | 6 votes |
@Test public void testDataWritesToSNS() { final PublishRequest request1 = createSampleMessage("my_first_message"); final PublishRequest request2 = createSampleMessage("my_second_message"); final TupleTag<PublishResult> results = new TupleTag<>(); final AmazonSNS amazonSnsSuccess = getAmazonSnsMockSuccess(); final PCollectionTuple snsWrites = p.apply(Create.of(request1, request2)) .apply( SnsIO.write() .withTopicName(topicName) .withRetryConfiguration( SnsIO.RetryConfiguration.create( 5, org.joda.time.Duration.standardMinutes(1))) .withAWSClientsProvider(new Provider(amazonSnsSuccess)) .withResultOutputTag(results)); final PCollection<Long> publishedResultsSize = snsWrites.get(results).apply(Count.globally()); PAssert.that(publishedResultsSize).containsInAnyOrder(ImmutableList.of(2L)); p.run().waitUntilFinish(); }
Example #21
Source File: NotificationsAutoConfiguration.java From genie with Apache License 2.0 | 6 votes |
/** * Create a {@link JobStateChangeSNSPublisher} unless one exists in the context already. * * @param snsClient the Amazon SNS client * @param properties configuration properties * @param registry the metrics registry * @return a {@link JobStateChangeSNSPublisher} */ @Bean @ConditionalOnProperty(value = SNSNotificationsProperties.ENABLED_PROPERTY, havingValue = "true") @ConditionalOnMissingBean(JobStateChangeSNSPublisher.class) public JobStateChangeSNSPublisher jobNotificationsSNSPublisher( final SNSNotificationsProperties properties, final MeterRegistry registry, final AmazonSNS snsClient ) { return new JobStateChangeSNSPublisher( snsClient, properties, registry, GenieObjectMapper.getMapper() ); }
Example #22
Source File: NotificationMessagingTemplateTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void convertAndSend_withPayloadAndSubject_shouldSetSubject() 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.sendNotification("My message", "My subject"); // Assert verify(amazonSns) .publish(new PublishRequest(physicalTopicName, "My message", "My subject") .withMessageAttributes(isNotNull())); }
Example #23
Source File: PubSubUtils.java From kork with Apache License 2.0 | 5 votes |
/** Returns the subscription arn resulting from subscribing the queueARN to the topicARN */ public static String subscribeToTopic(AmazonSNS amazonSNS, ARN topicARN, ARN queueARN) { return retrySupport.retry( () -> amazonSNS.subscribe(topicARN.getArn(), "sqs", queueARN.getArn()).getSubscriptionArn(), MAX_RETRIES, RETRY_BACKOFF, EXPONENTIAL); }
Example #24
Source File: NotificationStatusHandlerMethodArgumentResolverTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void resolveArgument_subscriptionRequest_createsValidSubscriptionStatus() throws Exception { // Arrange AmazonSNS amazonSns = mock(AmazonSNS.class); NotificationStatusHandlerMethodArgumentResolver resolver = new NotificationStatusHandlerMethodArgumentResolver( amazonSns); byte[] subscriptionRequestJsonContent = FileCopyUtils.copyToByteArray( new ClassPathResource("subscriptionConfirmation.json", getClass()) .getInputStream()); MockHttpServletRequest servletRequest = new MockHttpServletRequest(); servletRequest.setContent(subscriptionRequestJsonContent); MethodParameter methodParameter = new MethodParameter( ReflectionUtils.findMethod(NotificationMethods.class, "subscriptionMethod", NotificationStatus.class), 0); // Act Object resolvedArgument = resolver.resolveArgument(methodParameter, null, new ServletWebRequest(servletRequest), null); // Assert assertThat(resolvedArgument instanceof NotificationStatus).isTrue(); ((NotificationStatus) resolvedArgument).confirmSubscription(); verify(amazonSns, times(1)).confirmSubscription( "arn:aws:sns:eu-west-1:111111111111:mySampleTopic", "1111111111111111111111111111111111111111111111" + "1111111111111111111111111111111111111111111" + "1111111111111111111111111111111111111111111" + "1111111111111111111111111111111111111111111" + "11111111111111111111111111111111111"); }
Example #25
Source File: NotificationHandlerMethodArgumentResolverConfigurationUtils.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
public static HandlerMethodArgumentResolver getNotificationHandlerMethodArgumentResolver( AmazonSNS amazonSns) { HandlerMethodArgumentResolverComposite composite = new HandlerMethodArgumentResolverComposite(); composite.addResolver( new NotificationStatusHandlerMethodArgumentResolver(amazonSns)); composite.addResolver(new NotificationMessageHandlerMethodArgumentResolver()); composite.addResolver(new NotificationSubjectHandlerMethodArgumentResolver()); return composite; }
Example #26
Source File: PubSubUtils.java From kork with Apache License 2.0 | 5 votes |
/** * Ensure that the topic exists and has a policy granting the specified accounts permission to * publish messages to it */ public static String ensureTopicExists( AmazonSNS amazonSNS, ARN topicARN, AmazonPubsubSubscription subscription) { String createdTopicARN = retrySupport.retry( () -> amazonSNS.createTopic(topicARN.getName()).getTopicArn(), MAX_RETRIES, RETRY_BACKOFF, EXPONENTIAL); log.debug( (createdTopicARN.equals(topicARN.getArn())) ? "Reusing existing topic {}" : "Created topic {}", createdTopicARN); if (!subscription.getAccountIds().isEmpty()) { amazonSNS.setTopicAttributes( new SetTopicAttributesRequest() .withTopicArn(createdTopicARN) .withAttributeName("Policy") .withAttributeValue( buildSNSPolicy(new ARN(createdTopicARN), subscription.getAccountIds()).toJson())); } return createdTopicARN; }
Example #27
Source File: SNSPublisherProvider.java From kork with Apache License 2.0 | 5 votes |
@PostConstruct public void start() { if (properties == null) { return; } List<PubsubPublisher> publishers = new ArrayList<>(); properties .getSubscriptions() .forEach( (AmazonPubsubProperties.AmazonPubsubSubscription subscription) -> { ARN topicARN = new ARN(subscription.getTopicARN()); log.info("Bootstrapping SNS topic: {}", topicARN); AmazonSNS amazonSNS = AmazonSNSClientBuilder.standard() .withCredentials(awsCredentialsProvider) .withClientConfiguration(new ClientConfiguration()) .withRegion(topicARN.getRegion()) .build(); Supplier<Boolean> isEnabled = PubSubUtils.getEnabledSupplier(dynamicConfig, subscription, eurekaStatus); SNSPublisher publisher = new SNSPublisher(subscription, amazonSNS, isEnabled, registry, retrySupport); publishers.add(publisher); }); pubsubPublishers.putAll(publishers); }
Example #28
Source File: TemporarySQSQueue.java From front50 with Apache License 2.0 | 5 votes |
public TemporarySQSQueue( AmazonSQS amazonSQS, AmazonSNS amazonSNS, String snsTopicName, String instanceId) { this.amazonSQS = amazonSQS; this.amazonSNS = amazonSNS; String sanitizedInstanceId = getSanitizedInstanceId(instanceId); String snsTopicArn = getSnsTopicArn(amazonSNS, snsTopicName); String sqsQueueName = snsTopicName + "__" + sanitizedInstanceId; String sqsQueueArn = snsTopicArn.substring(0, snsTopicArn.lastIndexOf(":") + 1).replace("sns", "sqs") + sqsQueueName; this.temporaryQueue = createQueue(snsTopicArn, sqsQueueArn, sqsQueueName); }
Example #29
Source File: TopicMessageChannelTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test 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 assertThat(sent).isTrue(); assertThat(publishRequestArgumentCaptor.getValue().getMessageAttributes() .get(headerName).getBinaryValue()).isEqualTo(headerValue); assertThat(publishRequestArgumentCaptor.getValue().getMessageAttributes() .get(headerName).getDataType()) .isEqualTo(MessageAttributeDataTypes.BINARY); }
Example #30
Source File: NotificationMessagingTemplate.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
public NotificationMessagingTemplate(AmazonSNS amazonSns, DestinationResolver<String> destinationResolver, MessageConverter messageConverter) { super(destinationResolver); this.amazonSns = amazonSns; initMessageConverter(messageConverter); }