List of usage examples for com.amazonaws.services.sqs AmazonSQSClientBuilder standard
public static AmazonSQSClientBuilder standard()
From source file:com.netflix.spinnaker.echo.pubsub.amazon.SQSSubscriberProvider.java
License:Apache License
@PostConstruct public void start() { if (properties == null) { return;/*from w ww .j a v a2 s. co m*/ } 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()); SQSSubscriber worker = new SQSSubscriber(objectMapper, subscription, pubsubMessageHandler, AmazonSNSClientBuilder.standard().withCredentials(awsCredentialsProvider) .withClientConfiguration(new ClientConfiguration()).withRegion(queueArn.getRegion()) .build(), AmazonSQSClientBuilder.standard().withCredentials(awsCredentialsProvider) .withClientConfiguration(new ClientConfiguration()).withRegion(queueArn.getRegion()) .build(), () -> enabled.get(), 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); }
From source file:com.netflix.spinnaker.echo.pubsub.aws.SQSSubscriberProvider.java
License:Apache License
@PostConstruct public void start() { if (properties == null) { return;//from w w w .ja v a 2 s . co m } 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()); SQSSubscriber worker = new SQSSubscriber(objectMapper, subscription, pubsubMessageHandler, AmazonSNSClientBuilder.standard().withCredentials(awsCredentialsProvider) .withClientConfiguration(new ClientConfiguration()).withRegion(queueArn.getRegion()) .build(), AmazonSQSClientBuilder.standard().withCredentials(awsCredentialsProvider) .withClientConfiguration(new ClientConfiguration()).withRegion(queueArn.getRegion()) .build(), enabled::get, registry, jinjavaFactory, applicationEventPublisher); 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); }
From source file:com.streamsets.pipeline.stage.origin.sqs.SqsConsumer.java
License:Apache License
@Override protected List<ConfigIssue> init() { List<ConfigIssue> issues = super.init(); if (conf.region == AwsRegion.OTHER && (conf.endpoint == null || conf.endpoint.isEmpty())) { issues.add(getContext().createConfigIssue(Groups.SQS.name(), SQS_CONFIG_PREFIX + "endpoint", Errors.SQS_01));//from w ww . j ava 2 s . c om return issues; } // Propagate StringBuilder size to the service getContext().getService(DataFormatParserService.class).setStringBuilderPoolSize(getNumberOfThreads()); try { clientConfiguration = AWSUtil.getClientConfiguration(conf.proxyConfig); } catch (StageException e) { issues.add(getContext().createConfigIssue(Groups.SQS.name(), SQS_CONFIG_PREFIX + "proxyConfig", Errors.SQS_10, e.getMessage(), e)); return issues; } try { credentials = AWSUtil.getCredentialsProvider(conf.awsConfig); } catch (StageException e) { issues.add(getContext().createConfigIssue(Groups.SQS.name(), SQS_CONFIG_PREFIX + "awsConfig", Errors.SQS_11, e.getMessage(), e)); return issues; } AmazonSQS validationClient = AmazonSQSClientBuilder.standard().withRegion(conf.region.getId()) .withClientConfiguration(clientConfiguration).withCredentials(credentials).build(); for (int i = 0; i < conf.queuePrefixes.size(); i++) { final String queueNamePrefix = conf.queuePrefixes.get(i); ListQueuesResult result = validationClient.listQueues(new ListQueuesRequest(queueNamePrefix)); if (LOG.isDebugEnabled()) { LOG.debug("ListQueuesResult for prefix {}: {}", queueNamePrefix, result); } if (result.getQueueUrls().size() == 0) { //TODO: set index in issue when API-138 is implemented issues.add(getContext().createConfigIssue(Groups.SQS.name(), SQS_CONFIG_PREFIX + "queuePrefixes", Errors.SQS_02, queueNamePrefix)); } result.getQueueUrls().forEach(url -> queueUrlToPrefix.put(url, queueNamePrefix)); } if (queueUrlToPrefix.isEmpty()) { issues.add(getContext().createConfigIssue(Groups.SQS.name(), SQS_CONFIG_PREFIX + "queuePrefixes", Errors.SQS_09)); } return issues; }
From source file:io.konig.maven.CreateAwsSqsQueueAction.java
License:Apache License
public AwsDeployment from(String path) throws Exception { String cfTemplatePresent = System.getProperty("cfTemplatePresent"); if (cfTemplatePresent == null || cfTemplatePresent.equals("N")) { try {// ww w. j a v a2s . com File file = deployment.file(path); ObjectMapper mapper = new ObjectMapper(); S3Bucket bucket = mapper.readValue(file, S3Bucket.class); deployment.verifyAWSCredentials(); QueueConfiguration queueConfig = bucket.getNotificationConfiguration().getQueueConfiguration(); if (queueConfig != null && queueConfig.getQueue() != null) { String accountId = ""; if (System.getProperty("aws-account-id") != null) { accountId = System.getProperty("aws-account-id"); } Queue queue = queueConfig.getQueue(); Regions regions = Regions.fromName(queue.getRegion()); AmazonSQS sqs = AmazonSQSClientBuilder.standard().withCredentials(deployment.getCredential()) .withRegion(regions).build(); AmazonSNS sns = AmazonSNSClientBuilder.standard().withCredentials(deployment.getCredential()) .withRegion(regions).build(); CreateQueueResult result = sqs.createQueue(queue.getResourceName()); String topicArn = StringUtils.replaceOnce( bucket.getNotificationConfiguration().getTopicConfiguration().getTopicArn(), "${aws-account-id}", accountId); String queueArn = StringUtils.replaceOnce( bucket.getNotificationConfiguration().getQueueConfiguration().getQueueArn(), "${aws-account-id}", accountId); deployment.setResponse("Queue " + queueArn + " is created"); Policy policy = new Policy() .withStatements(new Statement(Effect.Allow).withPrincipals(Principal.AllUsers) .withActions(SQSActions.SendMessage).withResources(new Resource(queueArn)) .withConditions(ConditionFactory.newSourceArnCondition(topicArn))); Map<String, String> queueAttributes = new HashMap<String, String>(); queueAttributes.put(QueueAttributeName.Policy.toString(), policy.toJson()); deployment.setResponse("Queue Policy Configured : " + policy.toJson()); sqs.setQueueAttributes(new SetQueueAttributesRequest(result.getQueueUrl(), queueAttributes)); Topics.subscribeQueue(sns, sqs, topicArn, result.getQueueUrl()); deployment.setResponse( "Subscription is created : Topic [" + topicArn + "], Queue [" + queueArn + "]"); } else { deployment.setResponse("Queue Configuration Failed"); } } catch (Exception e) { throw e; } } else { deployment.setResponse("Queue will be created through cloud formation template"); } return deployment; }
From source file:io.konig.maven.DeleteAwsSQS.java
License:Apache License
public AwsDeployment from(String path) throws Exception { String cfTemplatePresent = System.getProperty("cfTemplatePresent"); if (cfTemplatePresent == null || cfTemplatePresent.equals("N")) { try {//w ww . j a v a 2 s .c om File file = deployment.file(path); ObjectMapper mapper = new ObjectMapper(); S3Bucket bucket = mapper.readValue(file, S3Bucket.class); deployment.verifyAWSCredentials(); QueueConfiguration queueConfig = bucket.getNotificationConfiguration().getQueueConfiguration(); if (queueConfig != null && queueConfig.getQueue() != null) { Queue queue = queueConfig.getQueue(); Regions regions = Regions.fromName(queue.getRegion()); AmazonSQS sqs = AmazonSQSClientBuilder.standard().withCredentials(deployment.getCredential()) .withRegion(regions).build(); String accountId = ""; if (System.getProperty("aws-account-id") != null) { accountId = System.getProperty("aws-account-id"); } String queueUrl = sqs.getQueueUrl(queueConfig.getQueue().getResourceName()).getQueueUrl(); String queueArn = StringUtils.replaceOnce(queueConfig.getQueueArn(), "${aws-account-id}", accountId); sqs.deleteQueue(queueUrl); deployment.setResponse("Queue " + queueArn + " is deleted"); } } catch (Exception e) { throw e; } } else { deployment.setResponse("Queue will be deleted through cloud formation stack"); } return deployment; }
From source file:org.apache.beam.sdk.io.aws.sqs.SqsUnboundedSource.java
License:Apache License
public SqsUnboundedSource(Read read, SqsConfiguration sqsConfiguration) { this.read = read; this.sqsConfiguration = sqsConfiguration; sqs = Suppliers.memoize((Supplier<AmazonSQS> & Serializable) () -> AmazonSQSClientBuilder.standard() .withClientConfiguration(sqsConfiguration.getClientConfiguration()) .withCredentials(sqsConfiguration.getAwsCredentialsProvider()) .withRegion(sqsConfiguration.getAwsRegion()).build()); }
From source file:org.finra.herd.dao.AwsClientFactory.java
License:Apache License
/** * Creates a client for accessing Amazon SQS. * * @param awsParamsDto the AWS related parameters DTO that includes optional proxy information * * @return the Amazon SQS client/*from w w w . j a v a 2s . co m*/ */ @Cacheable(DaoSpringModuleConfig.HERD_CACHE_NAME) public AmazonSQS getAmazonSQSClient(AwsParamsDto awsParamsDto) { // Construct and return a new client to invoke service methods on Amazon SQS using default credentials provider chain. return AmazonSQSClientBuilder.standard() .withClientConfiguration(awsHelper.getClientConfiguration(awsParamsDto)) .withRegion(awsParamsDto.getAwsRegionName()).build(); }
From source file:org.thingsboard.rule.engine.aws.sqs.TbSqsNode.java
License:Apache License
@Override public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException { this.config = TbNodeUtils.convert(configuration, TbSqsNodeConfiguration.class); AWSCredentials awsCredentials = new BasicAWSCredentials(this.config.getAccessKeyId(), this.config.getSecretAccessKey()); AWSStaticCredentialsProvider credProvider = new AWSStaticCredentialsProvider(awsCredentials); try {// w w w . ja v a 2 s . c o m this.sqsClient = AmazonSQSClientBuilder.standard().withCredentials(credProvider) .withRegion(this.config.getRegion()).build(); } catch (Exception e) { throw new TbNodeException(e); } }
From source file:org.thingsboard.server.extensions.sqs.plugin.SqsPlugin.java
License:Apache License
private void init() { AWSCredentials awsCredentials = new BasicAWSCredentials(configuration.getAccessKeyId(), configuration.getSecretAccessKey()); AmazonSQS sqs = AmazonSQSClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) .withRegion(Regions.fromName(configuration.getRegion())).build(); this.sqsMessageHandler = new SqsMessageHandler(sqs); }
From source file:org.thingsboard.server.extensions.sqs.SqsDemoClient.java
License:Apache License
public static void main(String[] args) { log.info("Starting SQS Demo Clinent..."); AWSCredentials awsCredentials = new BasicAWSCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY); AmazonSQS sqs = AmazonSQSClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) .withRegion(Regions.fromName(REGION)).build(); SqsDemoClient client = new SqsDemoClient(); client.pollMessages(sqs);/*from w w w .j ava 2 s . c o m*/ }