/** * Loads the test-specific Log4J configuration and resets the environment. */ public void setUp(String propertiesName) throws Exception { URL config = ClassLoader.getSystemResource(propertiesName); assertNotNull("missing configuration: " + propertiesName, config); LogManager.resetConfiguration(); PropertyConfigurator.configure(config); localLogger = Logger.getLogger(getClass()); runId = String.valueOf(System.currentTimeMillis()); resourceName = "SNSAppenderIntegrationTest-" + runId; System.setProperty("SNSAppenderIntegrationTest.resourceName", resourceName); localSNSclient = AmazonSNSClientBuilder.defaultClient(); localSQSclient = AmazonSQSClientBuilder.defaultClient(); }
public static void changeMessageVisibilityMultiple( String queue_url, int timeout) { AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient(); List<ChangeMessageVisibilityBatchRequestEntry> entries = new ArrayList<ChangeMessageVisibilityBatchRequestEntry>(); entries.add(new ChangeMessageVisibilityBatchRequestEntry( "unique_id_msg1", sqs.receiveMessage(queue_url) .getMessages() .get(0) .getReceiptHandle()) .withVisibilityTimeout(timeout)); entries.add(new ChangeMessageVisibilityBatchRequestEntry( "unique_id_msg2", sqs.receiveMessage(queue_url) .getMessages() .get(0) .getReceiptHandle()) .withVisibilityTimeout(timeout + 200)); sqs.changeMessageVisibilityBatch(queue_url, entries); }
/** * Returns a client instance for AWS SQS. * @return a client that talks to SQS */ public static AmazonSQS getClient() { if (sqsClient != null) { return sqsClient; } if (Config.IN_PRODUCTION) { sqsClient = AmazonSQSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider( new BasicAWSCredentials(Config.AWS_ACCESSKEY, Config.AWS_SECRETKEY))). withRegion(Config.AWS_REGION).build(); } else { sqsClient = AmazonSQSClientBuilder.standard(). withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("x", "x"))). withEndpointConfiguration(new EndpointConfiguration(LOCAL_ENDPOINT, "")).build(); } Para.addDestroyListener(new DestroyListener() { public void onDestroy() { sqsClient.shutdown(); } }); return sqsClient; }
@Bean public SQSConnectionFactory sqsConnectionFactory() throws JMSException { return new SQSConnectionFactory( new ProviderConfiguration(), AmazonSQSClientBuilder.standard() .withRegion(Regions.AP_SOUTHEAST_2) .withCredentials(new ProfileCredentialsProvider(CREDENTIALS_PROVIDER)) ); }
public static AmazonSQS createSqsClient(AWSCredentials credentials, ClientConfiguration cc, Regions region) { return AmazonSQSClientBuilder // .standard() // .withCredentials(new AWSStaticCredentialsProvider(credentials)) // .withRegion(region) // .build(); }
private AmazonSQS initializeSqs() { BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretyKey); AWSStaticCredentialsProvider provider = new AWSStaticCredentialsProvider(awsCredentials); return AmazonSQSClientBuilder.standard() .withCredentials(provider) .withRegion(Regions.US_EAST_2) .build(); }
@Override public AmazonSQS get(SqsModule.EndpointConfig config) { AmazonSQSClientBuilder builder = AmazonSQSClientBuilder.standard(); builder.withCredentials(credentialsProvider); if (config.endpoint().isPresent()) { builder.withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration(config.getEndpoint(), config.getRegionName()) ); } else { builder.withRegion(Regions.fromName(config.getRegionName())); } return builder.build(); }
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); }
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); }
public static void changeMessageVisibilitySingle( String queue_url, int timeout) { AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient(); // Get the receipt handle for the first message in the queue. String receipt = sqs.receiveMessage(queue_url) .getMessages() .get(0) .getReceiptHandle(); sqs.changeMessageVisibility(queue_url, receipt, timeout); }
public static void main(String[] args) { final String queue_name = "testQueue" + new Date().getTime(); AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient(); // first, create a queue (unless it exists already) try { CreateQueueResult cq_result = sqs.createQueue(queue_name); } catch (AmazonSQSException e) { if (!e.getErrorCode().equals("QueueAlreadyExists")) { throw e; } } final String queue_url = sqs.getQueueUrl(queue_name).getQueueUrl(); // Send some messages to the queue for (int i = 0; i < 20; i++) { sqs.sendMessage(queue_url, "This is message " + i); } // change visibility timeout (single) changeMessageVisibilitySingle(queue_url, 3600); // change visibility timeout (multiple) changeMessageVisibilityMultiple(queue_url, 2000); }
public static void main(String[] args) { final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient(); try { CreateQueueResult create_result = sqs.createQueue(QUEUE_NAME); } catch (AmazonSQSException e) { if (!e.getErrorCode().equals("QueueAlreadyExists")) { throw e; } } String queueUrl = sqs.getQueueUrl(QUEUE_NAME).getQueueUrl(); SendMessageRequest send_msg_request = new SendMessageRequest() .withQueueUrl(queueUrl) .withMessageBody("hello world") .withDelaySeconds(5); sqs.sendMessage(send_msg_request); // Send multiple messages to the queue SendMessageBatchRequest send_batch_request = new SendMessageBatchRequest() .withQueueUrl(queueUrl) .withEntries( new SendMessageBatchRequestEntry( "msg_1", "Hello from message 1"), new SendMessageBatchRequestEntry( "msg_2", "Hello from message 2") .withDelaySeconds(10)); sqs.sendMessageBatch(send_batch_request); // receive messages from the queue List<Message> messages = sqs.receiveMessage(queueUrl).getMessages(); // delete messages from the queue for (Message m : messages) { sqs.deleteMessage(queueUrl, m.getReceiptHandle()); } }
public CloudtrailSQSClient(Region region, String queueName, AWSAuthProvider authProvider, HttpUrl proxyUrl, ObjectMapper objectMapper) { AmazonSQSClientBuilder clientBuilder = AmazonSQSClientBuilder.standard().withRegion(region.getName()).withCredentials(authProvider); if (proxyUrl != null) { clientBuilder.withClientConfiguration(Proxy.forAWS(proxyUrl)); } this.sqs = clientBuilder.build(); this.queueName = queueName; this.objectMapper = objectMapper; }
private void buildSqsClient() { if (sqsClient == null) { sqsClient = AmazonSQSClientBuilder.standard() .withCredentials(config.getAwsCredentialsProvider()) .withRegion(config.getSqsRegion()) .build(); } }
public SQSConnectionFactory(ProviderConfiguration providerConfiguration, final AmazonSQSClientBuilder clientBuilder) { if (providerConfiguration == null) { throw new IllegalArgumentException("Provider configuration cannot be null"); } if (clientBuilder == null) { throw new IllegalArgumentException("AmazonSQS client builder cannot be null"); } this.providerConfiguration = providerConfiguration; this.amazonSQSClientSupplier = new AmazonSQSClientSupplier() { @Override public AmazonSQS get() { return clientBuilder.build(); } }; }
@Test public void canCreateFactoryWithCustomBuilder() throws JMSException { AmazonSQSClientBuilder clientBuilder = AmazonSQSClientBuilder.standard().withRegion(Regions.US_EAST_1); SQSConnectionFactory factory = new SQSConnectionFactory(new ProviderConfiguration(), clientBuilder); SQSConnection connection = factory.createConnection(); connection.close(); }
@Test public void factoryWithCustomBuilderWillCreateNewClient() throws JMSException { AmazonSQSClientBuilder clientBuilder = AmazonSQSClientBuilder.standard().withRegion(Regions.US_EAST_1); SQSConnectionFactory factory = new SQSConnectionFactory(new ProviderConfiguration(), clientBuilder); SQSConnection connection1 = factory.createConnection(); SQSConnection connection2 = factory.createConnection(); assertNotSame(connection1.getAmazonSQSClient(), connection2.getAmazonSQSClient()); connection1.close(); connection2.close(); }
private void createAmazonAPIClients() { cfnClient = AmazonCloudFormationClientBuilder.defaultClient(); ec2Client = AmazonEC2ClientBuilder.defaultClient(); snsClient = AmazonSNSClientBuilder.defaultClient(); sqsClient = AmazonSQSClientBuilder.defaultClient(); elbClient = AmazonElasticLoadBalancingClientBuilder.defaultClient(); s3Client = AmazonS3ClientBuilder.defaultClient(); rdsClient = AmazonRDSClientBuilder.defaultClient(); iamClient = AmazonIdentityManagementClientBuilder.defaultClient(); }
public static AmazonSQSClient createSQSClient() { BasicCredentialsProvider credentials = BasicCredentialsProvider.standard(); AmazonSQSClient client = !credentials.isValid() ? null : (AmazonSQSClient) AmazonSQSClientBuilder.standard() .withCredentials(credentials) .withRegion("eu-west-1").build(); return client; }
@Test(expected = NullPointerException.class) public void testBucketNameAndS3FactoryMustBothBeSpecified() { Sqs.queueName("queue").sqsFactory(() -> AmazonSQSClientBuilder.defaultClient()).bucketName(null) .s3Factory(() -> AmazonS3ClientBuilder.defaultClient()).messages(); }
public void init(AWSKafkaConfig config){ this.config = config; deDuplicationId = config.getDeDeupPrefix(); mXmitDisable = config.getAwsXmitDisable(); SQSConnectionFactory connectionFactory = new SQSConnectionFactory( new ProviderConfiguration(), AmazonSQSClientBuilder.standard() .withRegion(config.getRegions()) .withCredentials(config.getCredentialsProvider()) ); try{ mPreProcessor = config.getPre(); mXmitReplacement = config.getReplaceXmit(this); // Create the connection. connection = connectionFactory.createConnection(); // Create the queue if needed //ExampleCommon.ensureQueueExists(connection, config.getQueueName()); // Create the session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); producer = session.createProducer( session.createQueue( config.getQueueName() ) ); // Get the wrapped client AmazonSQSMessagingClientWrapper client = connection.getWrappedAmazonSQSClient(); // Create an Amazon SQS queue if it does not already exist if (!client.queueExists(config.getQueueName())) { Map<String, String> attributes = new HashMap<String, String>(); attributes.put(config.getQueueName(), "true"); attributes.put("ContentBasedDeduplication", "true"); client.createQueue(new CreateQueueRequest().withQueueName(config.getQueueName()).withAttributes(attributes)); } }catch(JMSException e){ } }
LazyAmazonSQSClient(Builder builder) { this.builder = AmazonSQSClientBuilder.standard() .withEndpointConfiguration(builder.endpointConfiguration) .withCredentials(builder.credentialsProvider); }
public SQSHostMonitorLookup( Set<String> contactGroups ) throws CandlestackPropertiesException { this.contactGroups = contactGroups; queueNamePrefix = GlobalAWSProperties.getSQSQueueNamePrefix(); queueNameRegex = GlobalAWSProperties.getSQSQueueNameRegex(); monitorDeadLetter = GlobalAWSProperties.isSQSMonitorDeadLetterEnabled(); cloudWatchMetrics = GlobalAWSProperties.getSQSCloudwatchMetricsToMonitor(); queueAttributes = GlobalAWSProperties.getSQSQueueAttributesToMonitor(); sqsClient = AmazonSQSClientBuilder.standard().withRegion( GlobalAWSProperties.getRegion() ).build(); }
public SQSMetricsFetcher() throws CandlestackException { super( SQSUtil.TYPE_NAME, GlobalAWSProperties.getSQSMetricsFetcherSleep() ); queueNamePrefix = GlobalAWSProperties.getSQSQueueNamePrefix(); queueNameRegex = GlobalAWSProperties.getSQSQueueNameRegex(); monitorDeadLetter = GlobalAWSProperties.isSQSMonitorDeadLetterEnabled(); queueAttributes = GlobalAWSProperties.getSQSQueueAttributesToFetch().stream().map( attribute -> attribute.name() ).collect( Collectors.toList() ); cloudWatchMetrics = GlobalAWSProperties.getSQSCloudwatchMetricsToFetch(); sqsClient = AmazonSQSClientBuilder.standard().withRegion( GlobalAWSProperties.getRegion() ).build(); cloudWatchAccessor = CloudWatchAccessor.getInstance(); }
public static void main(String[] args) { final String USAGE = "To run this example, supply the name of a queue to create and\n" + "queue url of an existing queue.\n\n" + "Ex: LongPolling <unique-queue-name> <existing-queue-url>\n"; if (args.length != 2) { System.out.println(USAGE); System.exit(1); } String queue_name = args[0]; String queue_url = args[1]; final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient(); // Enable long polling when creating a queue CreateQueueRequest create_request = new CreateQueueRequest() .withQueueName(queue_name) .addAttributesEntry("ReceiveMessageWaitTimeSeconds", "20"); try { sqs.createQueue(create_request); } catch (AmazonSQSException e) { if (!e.getErrorCode().equals("QueueAlreadyExists")) { throw e; } } // Enable long polling on an existing queue SetQueueAttributesRequest set_attrs_request = new SetQueueAttributesRequest() .withQueueUrl(queue_url) .addAttributesEntry("ReceiveMessageWaitTimeSeconds", "20"); sqs.setQueueAttributes(set_attrs_request); // Enable long polling on a message receipt ReceiveMessageRequest receive_request = new ReceiveMessageRequest() .withQueueUrl(queue_url) .withWaitTimeSeconds(20); sqs.receiveMessage(receive_request); }
@Bean public AmazonSQS amazonSQS(final SQSConfiguration sqsConfiguration) { return AmazonSQSClientBuilder.standard().withRegion(sqsConfiguration.getRegion()).build(); }
public SQSConnectionFactory(ProviderConfiguration providerConfiguration) { this(providerConfiguration, AmazonSQSClientBuilder.standard()); }
public static AmazonSQS createSQSClient() { return AmazonSQSClientBuilder.defaultClient(); }