com.amazonaws.services.sns.AmazonSNSClientBuilder Java Examples
The following examples show how to use
com.amazonaws.services.sns.AmazonSNSClientBuilder.
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: SNSInventoryUtilTest.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch SNS topics test. * * @throws Exception the exception */ @SuppressWarnings("static-access") @Test public void fetchSNSTopicsTest() throws Exception { mockStatic(AmazonSNSClientBuilder.class); AmazonSNSClient snsClient = PowerMockito.mock(AmazonSNSClient.class); AmazonSNSClientBuilder amazonSNSClientBuilder = PowerMockito.mock(AmazonSNSClientBuilder.class); AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class); PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider); when(amazonSNSClientBuilder.standard()).thenReturn(amazonSNSClientBuilder); when(amazonSNSClientBuilder.withCredentials(anyObject())).thenReturn(amazonSNSClientBuilder); when(amazonSNSClientBuilder.withRegion(anyString())).thenReturn(amazonSNSClientBuilder); when(amazonSNSClientBuilder.build()).thenReturn(snsClient); ListSubscriptionsResult listSubscriptionDefinitionsResult = new ListSubscriptionsResult(); List<Subscription> subscriptionList = new ArrayList<>(); subscriptionList.add(new Subscription()); listSubscriptionDefinitionsResult.setSubscriptions(subscriptionList); when(snsClient.listSubscriptions( new ListSubscriptionsRequest())).thenReturn(listSubscriptionDefinitionsResult); assertThat(snsInventoryUtil.fetchSNSTopics(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "skipRegions", "account","accountName").size(), is(1)); }
Example #2
Source File: AWSSNSMetaDataExtension.java From syndesis with Apache License 2.0 | 6 votes |
@Override public Optional<MetaData> meta(Map<String, Object> parameters) { final String accessKey = ConnectorOptions.extractOption(parameters, "accessKey"); final String secretKey = ConnectorOptions.extractOption(parameters, "secretKey"); final String region = ConnectorOptions.extractOption(parameters, "region"); AmazonSNSClientBuilder clientBuilder; AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); clientBuilder = AmazonSNSClientBuilder.standard().withCredentials(credentialsProvider); clientBuilder = clientBuilder.withRegion(Regions.valueOf(region)); AmazonSNS sqsClient = clientBuilder.build(); try { ListTopicsResult result = sqsClient.listTopics(); Set<String> setTopic = new HashSet<String>(); if (result.getTopics() != null) { for (Topic entry : result.getTopics()) { setTopic.add(entry.getTopicArn()); } } return Optional.of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain").withAttribute(MetaData.JAVA_TYPE, String.class) .withPayload(setTopic).build()); } catch (Exception e) { throw new IllegalStateException("Get information about existing topics with has failed.", e); } }
Example #3
Source File: TracingHandlerTest.java From aws-xray-sdk-java with Apache License 2.0 | 6 votes |
@Test public void testSNSPublish() { // Setup test // reference : https://docs.aws.amazon.com/sns/latest/api/API_Publish.html final String publishResponse = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<PublishResponse xmlns=\"http://sns.amazonaws.com/doc/2010-03-31/\">" + "<PublishResult><MessageId>94f20ce6-13c5-43a0-9a9e-ca52d816e90b</MessageId>" + "</PublishResult>" + "</PublishResponse>"; final String topicArn = "testTopicArn"; AmazonSNS sns = AmazonSNSClientBuilder .standard() .withRequestHandlers(new TracingHandler()) .withRegion(Regions.US_EAST_1) .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("fake", "fake"))) .build(); mockHttpClient(sns, publishResponse); // Test logic Segment segment = AWSXRay.beginSegment("test"); sns.publish(new PublishRequest(topicArn, "testMessage")); Assert.assertEquals(1, segment.getSubsegments().size()); Assert.assertEquals("Publish", segment.getSubsegments().get(0).getAws().get("operation")); Assert.assertEquals(topicArn, segment.getSubsegments().get(0).getAws().get("topic_arn")); }
Example #4
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 #5
Source File: AwsClientFactory.java From herd with Apache License 2.0 | 5 votes |
/** * Creates a client for accessing Amazon SNS. * * @param awsParamsDto the AWS related parameters DTO that includes optional proxy information * * @return the Amazon SNS client */ @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME) public AmazonSNS getAmazonSNSClient(AwsParamsDto awsParamsDto) { // Construct and return a new client to invoke service methods on Amazon SNS using default credentials provider chain. return AmazonSNSClientBuilder.standard().withClientConfiguration(awsHelper.getClientConfiguration(awsParamsDto)) .withRegion(awsParamsDto.getAwsRegionName()).build(); }
Example #6
Source File: AWSAutoConfiguration.java From genie with Apache License 2.0 | 5 votes |
/** * Create a named {@link AmazonSNS} client to be used by JobNotification SNS publishers, unless a bean by that * name already exists in context. * * @param credentialsProvider The credentials provider * @param awsRegionProvider The region provider * @param clientConfiguration The client configuration * @return an {@link AmazonSNS} client */ @Bean(name = SNS_CLIENT_BEAN_NAME) @ConditionalOnMissingBean(name = SNS_CLIENT_BEAN_NAME) @ConditionalOnProperty(value = SNSNotificationsProperties.ENABLED_PROPERTY, havingValue = "true") public AmazonSNS jobNotificationsSNSClient( final AWSCredentialsProvider credentialsProvider, final AwsRegionProvider awsRegionProvider, @Qualifier(SNS_CLIENT_CONFIGURATION_BEAN_NAME) final ClientConfiguration clientConfiguration ) { return AmazonSNSClientBuilder.standard() .withCredentials(credentialsProvider) .withRegion(awsRegionProvider.getRegion()) .withClientConfiguration(clientConfiguration) .build(); }
Example #7
Source File: SNSUtils.java From wildfly-camel with Apache License 2.0 | 5 votes |
public static AmazonSNSClient createNotificationClient() { BasicCredentialsProvider credentials = BasicCredentialsProvider.standard(); AmazonSNSClient client = !credentials.isValid() ? null : (AmazonSNSClient) AmazonSNSClientBuilder.standard() .withCredentials(credentials) .withRegion("eu-west-1") .build(); return client; }
Example #8
Source File: S3Config.java From front50 with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty("spinnaker.s3.eventing.enabled") public AmazonSNS awsSNSClient( AWSCredentialsProvider awsCredentialsProvider, S3MetadataStorageProperties s3Properties) { return AmazonSNSClientBuilder.standard() .withCredentials(awsCredentialsProvider) .withClientConfiguration(new ClientConfiguration()) .withRegion(s3Properties.getRegion()) .build(); }
Example #9
Source File: PushSnsService.java From oxAuth with MIT License | 5 votes |
public AmazonSNS createSnsClient(String accessKey, String secretKey, String region) { String decryptedAccessKey = encryptionService.decrypt(accessKey, true); String decryptedSecretKey = encryptionService.decrypt(secretKey, true); BasicAWSCredentials credentials = new BasicAWSCredentials(decryptedAccessKey, decryptedSecretKey); AmazonSNS snsClient = AmazonSNSClientBuilder.standard().withRegion(Regions.fromName(region)).withCredentials(new AWSStaticCredentialsProvider(credentials)).build(); return snsClient; }
Example #10
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 #11
Source File: BasicSnsProvider.java From beam with Apache License 2.0 | 5 votes |
@Override public AmazonSNS createSnsPublisher() { return AmazonSNSClientBuilder.standard() .withCredentials(getCredentialsProvider()) .withRegion(region) .build(); }
Example #12
Source File: SNSPublishStep.java From pipeline-aws-plugin with Apache License 2.0 | 5 votes |
@Override protected Void run() throws Exception { final String topicArn = this.step.getTopicArn(); final String subject = this.step.getSubject(); final String message = this.step.getMessage(); final Map<String, String> messageAttributes = this.step.getMessageAttributes(); TaskListener listener = this.getContext().get(TaskListener.class); AmazonSNS snsClient = AWSClientFactory.create(AmazonSNSClientBuilder.standard(), this.getContext()); listener.getLogger().format("Publishing notification %s to %s %n", subject, topicArn); PublishRequest publishRequest = new PublishRequest() .withTopicArn(topicArn).withMessage(message).withSubject(subject); if (messageAttributes != null && !messageAttributes.isEmpty()) { for (Map.Entry<String, String> entry : messageAttributes.entrySet()) { MessageAttributeValue value = new MessageAttributeValue(); value.setStringValue(entry.getValue()); value.setDataType(STRING_DATATYPE); publishRequest.addMessageAttributesEntry(entry.getKey(), value); } } PublishResult result = snsClient.publish(publishRequest); listener.getLogger().format("Message published as %s %n", result.getMessageId()); return null; }
Example #13
Source File: AmazonDockerClientsHolder.java From spring-localstack with Apache License 2.0 | 5 votes |
@Override public AmazonSNS amazonSNS() { return decorateWithConfigsAndBuild( AmazonSNSClientBuilder.standard(), LocalstackDocker::getEndpointSNS ); }
Example #14
Source File: TerraformLaunchRequestHandler.java From aws-service-catalog-terraform-reference-architecture with Apache License 2.0 | 5 votes |
private void publishNotification(String hubSnsTopicArn, String cfnRequest, Map<String, MessageAttributeValue> messageAttributes) { String region = ArnParser.getRegion(hubSnsTopicArn); AmazonSNS sns = AmazonSNSClientBuilder.standard() .withRegion(region) .build(); sns.publish(new PublishRequest() .withTopicArn(hubSnsTopicArn) .withMessage(cfnRequest) .withSubject("AWS CloudFormation custom resource request with requester AccountId") .withMessageAttributes(messageAttributes) ); }
Example #15
Source File: SQSSubscriberProvider.java From echo with Apache License 2.0 | 4 votes |
@PostConstruct public void start() { Preconditions.checkNotNull( properties, "Can't initialize SQSSubscriberProvider with null properties"); ExecutorService executorService = Executors.newFixedThreadPool(properties.getSubscriptions().size()); List<PubsubSubscriber> subscribers = new ArrayList<>(); properties .getSubscriptions() .forEach( (AmazonPubsubProperties.AmazonPubsubSubscription subscription) -> { log.info("Bootstrapping SQS for SNS topic: {}", subscription.getTopicARN()); if (subscription.getTemplatePath() != null && !subscription.getTemplatePath().equals("")) { log.info( "Using template: {} for subscription: {}", subscription.getTemplatePath(), subscription.getName()); } ARN queueArn = new ARN(subscription.getQueueARN()); Optional<MessageArtifactTranslator> messageArtifactTranslator = Optional.empty(); if (subscription.getMessageFormat() != AmazonPubsubProperties.MessageFormat.NONE) { messageArtifactTranslator = Optional.ofNullable(subscription.readTemplatePath()) .map(messageArtifactTranslatorFactory::createJinja); } EventCreator eventCreator = new PubsubEventCreator(messageArtifactTranslator); SQSSubscriber worker = new SQSSubscriber( objectMapper, subscription, pubsubMessageHandlerFactory.create(eventCreator), AmazonSNSClientBuilder.standard() .withCredentials(awsCredentialsProvider) .withClientConfiguration(new ClientConfiguration()) .withRegion(queueArn.getRegion()) .build(), AmazonSQSClientBuilder.standard() .withCredentials(awsCredentialsProvider) .withClientConfiguration(new ClientConfiguration()) .withRegion(queueArn.getRegion()) .build(), isEnabledSupplier(), registry); try { executorService.submit(worker); subscribers.add(worker); log.debug("Created worker for subscription: {}", subscription.getName()); } catch (RejectedExecutionException e) { log.error("Could not start " + worker.getWorkerName(), e); } }); pubsubSubscribers.putAll(subscribers); }
Example #16
Source File: SQSSubscriberProvider.java From kork with Apache License 2.0 | 4 votes |
@PostConstruct public void start() { Preconditions.checkNotNull( properties, "Can't initialize SQSSubscriberProvider with null properties"); ExecutorService executorService = Executors.newFixedThreadPool(properties.getSubscriptions().size()); List<PubsubSubscriber> subscribers = new ArrayList<>(); properties .getSubscriptions() .forEach( (AmazonPubsubProperties.AmazonPubsubSubscription subscription) -> { log.info("Bootstrapping SQS for SNS topic: {}", subscription.getTopicARN()); ARN queueArn = new ARN(subscription.getQueueARN()); ARN topicArn = new ARN(subscription.getTopicARN()); SQSSubscriber worker = new SQSSubscriber( subscription, pubsubMessageHandlerFactory.create(subscription), messageAcknowledger, AmazonSNSClientBuilder.standard() .withCredentials(awsCredentialsProvider) .withClientConfiguration(new ClientConfiguration()) .withRegion(topicArn.getRegion()) .build(), AmazonSQSClientBuilder.standard() .withCredentials(awsCredentialsProvider) .withClientConfiguration(new ClientConfiguration()) .withRegion(queueArn.getRegion()) .build(), PubSubUtils.getEnabledSupplier(dynamicConfig, subscription, eurekaStatus), registry); try { executorService.submit(worker); subscribers.add(worker); log.debug( "Created worker {} for subscription: {}", worker.getWorkerName(), subscription.getName()); } catch (RejectedExecutionException e) { log.error("Could not start {}", worker.getWorkerName(), e); } }); pubsubSubscribers.putAll(subscribers); }
Example #17
Source File: AwsSessionFactory.java From Gatekeeper with Apache License 2.0 | 4 votes |
public AmazonSNS createSnsSession(){ return AmazonSNSClientBuilder .standard() .build(); }
Example #18
Source File: LambdaSnsPublishHandler.java From Serverless-Programming-Cookbook with MIT License | 4 votes |
public LambdaSnsPublishHandler() { this.snsClient = AmazonSNSClientBuilder.standard() .withRegion(System.getenv("AWS_REGION")) .build(); }
Example #19
Source File: SnsWebhookManager.java From Singularity with Apache License 2.0 | 4 votes |
@Inject public SnsWebhookManager( @Singularity ObjectMapper objectMapper, SingularityConfiguration configuration, SingularityManagedThreadPoolFactory threadPoolFactory, WebhookManager webhookManager ) { this.objectMapper = objectMapper; this.webhookConf = configuration.getWebhookQueueConfiguration(); if ( webhookConf.getAwsAccessKey().isPresent() && webhookConf.getAwsSecretKey().isPresent() ) { this.snsClient = AmazonSNSClient .builder() .withCredentials( new AWSStaticCredentialsProvider( new BasicAWSCredentials( webhookConf.getAwsAccessKey().get(), webhookConf.getAwsSecretKey().get() ) ) ) .withClientConfiguration( new ClientConfiguration() .withMaxConnections(configuration.getMaxConcurrentWebhooks()) .withConnectionTimeout(webhookConf.getSnsConnectTimeout()) .withRequestTimeout(webhookConf.getSnsRequestTimeout()) .withSocketTimeout(webhookConf.getSnsSocketTimeout()) .withClientExecutionTimeout(webhookConf.getSnsTotalTimeout()) ) .withRegion(webhookConf.getAwsRegion().orElse("us-east-1")) .build(); } else { this.snsClient = AmazonSNSClientBuilder.defaultClient(); } this.webhookManager = webhookManager; this.publishExecutor = threadPoolFactory.get("webhook-publish", configuration.getMaxConcurrentWebhooks()); this.typeToArn = new ConcurrentHashMap<>(); }
Example #20
Source File: SpringCloudAwsTestUtil.java From tutorials with MIT License | 4 votes |
public static AmazonSNS amazonSNS() { return AmazonSNSClientBuilder.standard() .withCredentials(awsCredentialsProvider()) .withRegion(defaultRegion) .build(); }