@Activate protected void start(SmsConfig smsConfig) { this.smsAttributes = new HashMap<>(); this.smsAttributes.put("AWS.SNS.SMS.SenderID", new MessageAttributeValue() .withStringValue(smsConfig.senderId()) .withDataType("String")); this.smsAttributes.put("AWS.SNS.SMS.SMSType", new MessageAttributeValue() .withStringValue(smsConfig.smsType()) .withDataType("String")); try { this.asyncSNS = AmazonSNSAsyncClient.asyncBuilder() .withEndpointConfiguration(AwsUtil.getEndpointConfig(smsConfig.serviceEndpoint(), smsConfig.signingRegion())) .withCredentials(AwsUtil.getCredentialsProvider(smsConfig.accessKey(), smsConfig.secretKey())) .build(); } catch (Exception ex) { LOGGER.error("Exception while starting SmsService!!", ex); throw new AwsException(ex.getMessage(), ex); } }
SnsListener(AmazonSNSAsyncClient sns, ListenerConfig config, Clock clock) { this.clock = clock; LOG.info("Starting listener, topics: start={}, success={}, fail={}", config.getStartTopic(), config.getSuccessTopic(), config.getFailTopic()); this.sns = sns; this.config = config; ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); startWriter = mapper.writer(); }
@Bean AmazonSNSAsyncClient amazonSNS(ListenerConfig config, AWSCredentialsProvider awsCredentialsProvider) { AmazonSNSAsyncClient client = new AmazonSNSAsyncClient(awsCredentialsProvider, new ClientConfiguration().withRetryPolicy(PredefinedRetryPolicies.getDefaultRetryPolicy()), Executors.newSingleThreadScheduledExecutor()); client.setRegion(Region.getRegion(Regions.fromName(config.getRegion()))); return client; }
/** * If SNS notifications are desired and no existing client has been created elsewhere * in the application create a default client here. * @param config The system configuration abstraction to use * @param registry registry for spectator * @return The configured SNS client */ //TODO: See what spring-cloud-aws would provide automatically... @Bean @ConditionalOnMissingBean(AmazonSNSAsync.class) public AmazonSNSAsync amazonSNS(final Config config, final Registry registry) { final ExecutorService executor = Executors.newFixedThreadPool(config.getSNSClientThreadCount(), new ThreadFactoryBuilder().setNameFormat("metacat-sns-pool-%d").build()); RegistryUtil.registerThreadPool(registry, "metacat-sns-pool", (ThreadPoolExecutor) executor); return new AmazonSNSAsyncClient(DefaultAWSCredentialsProviderChain.getInstance(), executor); }
@Override protected void doStart() { sns = new AmazonSNSAsyncClient( getCredentials(), getClientConfiguration(), Executors.newFixedThreadPool(getThreadPoolSize()) ); sns.setRegion(RegionUtils.getRegion(region)); }
/** * Creates Amazon SNS client for given endpoint using the provided credentials. * * @param awsCredentials AWS credentials with access to the endpoint, or null to use default aws credentials. * @return Amazon SNS client. */ private static AmazonSNSAsync createInstance(AWSCredentials awsCredentials) { if (awsCredentials == null) { return new AmazonSNSAsyncClient(); } else { return new AmazonSNSAsyncClient(awsCredentials); } }
public S3Publisher(Config config, FileManager fileManager) { this.config = config; this.fileManager = fileManager; client = new AmazonSNSAsyncClient(config.getAWSCredentials()); topic = "S3Sync_" + config.getBucketName() + "_topic"; createTopic(); }
@Autowired public SnsListener(AmazonSNSAsyncClient sns, ListenerConfig config) { this(sns, config, Clock.DEFAULT); }
/** * The Asynchronous SNS client is used for publishing events to SNS. */ private AmazonSNSAsyncClient createAsyncSNSClient( final Region region, final ExecutorService executor ) { final UsergridAwsCredentialsProvider ugProvider = new UsergridAwsCredentialsProvider(); final AmazonSNSAsyncClient sns = new AmazonSNSAsyncClient( ugProvider.getCredentials(), clientConfiguration, executor ); sns.setRegion( region ); return sns; }