com.amazonaws.services.sqs.AmazonSQS Java Examples
The following examples show how to use
com.amazonaws.services.sqs.AmazonSQS.
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: VisibilityTimeout.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
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); }
Example #2
Source File: HerdApiClientOperations.java From herd with Apache License 2.0 | 6 votes |
/** * Gets BusinessObjectDataKey from SQS message * * @param client the AWS SQS client * @param queueUrl the AWS SQS queue url * * @return BusinessObjectDataKey * @throws IOException if fails to retrieve BusinessObjectDataKey from SQS message * @throws ApiException if fails to make API call */ @Retryable(value = ApiException.class, backoff = @Backoff(delay = 2000, multiplier = 2)) BusinessObjectDataKey getBdataKeySqs(AmazonSQS client, String queueUrl) throws IOException, ApiException { ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest().withMaxNumberOfMessages(MAX_NUM_MESSAGES).withQueueUrl(queueUrl).withWaitTimeSeconds(WAIT_TIME_SECS) .withVisibilityTimeout(VISIBILITY_TIMEOUT_SECS); LOGGER.info("Checking queue"); ReceiveMessageResult receiveMessageResult = client.receiveMessage(receiveMessageRequest); if (receiveMessageResult != null && receiveMessageResult.getMessages() != null && receiveMessageResult.getMessages().size() > 0) { List<Message> sqsMessageList = receiveMessageResult.getMessages(); LOGGER.info("Scanning {} messages for {} and {}", sqsMessageList.size(), SEARCH_KEYWORD_1, SEARCH_KEYWORD_2); // Get message type BUS_OBJCT_DATA_STTS_CHG for (Message sqsMessage : sqsMessageList) { String receivedMessageBody = sqsMessage.getBody(); if (receivedMessageBody.contains(SEARCH_KEYWORD_1) && receivedMessageBody.contains(SEARCH_KEYWORD_2)) { LOGGER.info("Received Message: {}", receivedMessageBody); return mapJsontoBdataKey(receivedMessageBody).getBusinessObjectDataKey(); } } } throw new ApiException("No SQS message found in queue: " + queueUrl); }
Example #3
Source File: AmazonSQSExtendedClientTest.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 6 votes |
@Test public void testReceiveMessageMultipleTimesDoesNotAdditionallyAlterReceiveMessageRequest() { ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withLargePayloadSupportEnabled(mockS3, S3_BUCKET_NAME); AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); when(mockSqsBackend.receiveMessage(isA(ReceiveMessageRequest.class))).thenReturn(new ReceiveMessageResult()); ReceiveMessageRequest messageRequest = new ReceiveMessageRequest(); ReceiveMessageRequest expectedRequest = new ReceiveMessageRequest() .withMessageAttributeNames(SQSExtendedClientConstants.RESERVED_ATTRIBUTE_NAME); sqsExtended.receiveMessage(messageRequest); Assert.assertEquals(expectedRequest, messageRequest); sqsExtended.receiveMessage(messageRequest); Assert.assertEquals(expectedRequest, messageRequest); }
Example #4
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 #5
Source File: MockSqsOperationsImpl.java From herd with Apache License 2.0 | 6 votes |
@Override public SendMessageResult sendMessage(String queueName, String messageText, Map<String, MessageAttributeValue> messageAttributes, AmazonSQS amazonSQS) { // Throw a throttling exception for a specific queue name for testing purposes. if (queueName.equals(MockAwsOperationsHelper.AMAZON_THROTTLING_EXCEPTION)) { AmazonServiceException throttlingException = new AmazonServiceException("test throttling exception"); throttlingException.setErrorCode("ThrottlingException"); throw throttlingException; } // Throw an illegal state exception for a specific queue name for testing purposes. if (queueName.equals(MOCK_SQS_QUEUE_NOT_FOUND_NAME)) { throw new IllegalStateException(String.format("AWS SQS queue with \"%s\" name not found.", queueName)); } // Nothing else to do in the normal case since our unit tests aren't reading messages once they have been published. return new SendMessageResult().withMessageId(AbstractDaoTest.MESSAGE_ID); }
Example #6
Source File: SpringCloudSQSLiveTest.java From tutorials with MIT License | 6 votes |
@Test public void whenMessageSentAndVerified_thenSuccess() throws InterruptedException { String message = "Hello World"; springCloudSQS.send(sendQueueName, message); AmazonSQS amazonSQS = SpringCloudAwsTestUtil.amazonSQS(); ReceiveMessageRequest request = new ReceiveMessageRequest(sendQueueURl); request.setMaxNumberOfMessages(1); ReceiveMessageResult result = null; do { result = amazonSQS.receiveMessage(request); if (result.getMessages().size() == 0) { logger.info("Message not received at first time, waiting for 1 second"); } } while (result.getMessages().size() == 0); assertThat(result.getMessages().get(0).getBody()).isEqualTo(message); // Delete message so that it doen't interfere with other test amazonSQS.deleteMessage(sendQueueURl, result.getMessages().get(0).getReceiptHandle()); }
Example #7
Source File: ReceiveQueueBuffer.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
public ReceiveQueueBuffer(AmazonSQS sqsClient, ScheduledExecutorService waitTimer, String queueUrl) { this.sqsClient = sqsClient; this.waitTimer = waitTimer; if (queueUrl.endsWith(".fifo")) { throw new IllegalArgumentException("FIFO queues are not yet supported: " + queueUrl); } GetQueueAttributesRequest getQueueAttributesRequest = new GetQueueAttributesRequest().withQueueUrl(queueUrl) .withAttributeNames(QueueAttributeName.ReceiveMessageWaitTimeSeconds.toString(), QueueAttributeName.VisibilityTimeout.toString()); // TODO-RS: UserAgent? Map<String, String> attributes = sqsClient.getQueueAttributes(getQueueAttributesRequest).getAttributes(); long visibilityTimeoutSeconds = Long.parseLong(attributes.get("VisibilityTimeout")); defaultVisibilityTimeoutNanos = TimeUnit.SECONDS.toNanos(visibilityTimeoutSeconds); long waitTimeSeconds = Long.parseLong(attributes.get("ReceiveMessageWaitTimeSeconds")); defaultWaitTimeNanos = TimeUnit.SECONDS.toNanos(waitTimeSeconds); }
Example #8
Source File: TagTest.java From herd-mdl with Apache License 2.0 | 6 votes |
@Test public void testSqsTagsAreSameAsHerdEC2Stack() throws Exception { String sqsNamePrefix = INSTANCE_NAME; String herdStackNamePrefix = APP_STACK_NAME + "-MdlStack-"; CloudFormationClient cloudFormationClient = new CloudFormationClient(APP_STACK_NAME); List<Tag> stackTags = cloudFormationClient.getStackByNamePrefix(herdStackNamePrefix).getTags(); System.out.println("Listing all queues with prefix: " + sqsNamePrefix); AmazonSQS sqs = AmazonSQSClientBuilder.standard().withRegion(Regions.getCurrentRegion().getName()) .withCredentials(new InstanceProfileCredentialsProvider(true)).build(); List<String> queueUrls = sqs.listQueues(sqsNamePrefix).getQueueUrls(); assertEquals(2, queueUrls.size(), "2 queues are expected"); for (String queueUrl : queueUrls) { System.out.println("QueueUrl: " + queueUrl); Map<String, String> sqsTags = sqs.listQueueTags(queueUrl).getTags(); LogVerification("Verify sqs tags are the same as herd stack"); stackTags.forEach(tag -> { String key = tag.getKey(); assertTrue(sqsTags.containsKey(key)); assertEquals(tag.getValue(), sqsTags.get(key)); }); } }
Example #9
Source File: SqsQueueResourceTest.java From Cheddar with Apache License 2.0 | 5 votes |
@Before public void setUp() { queueName = randomString(); queueUrl = randomString(); amazonSqsClient = mock(AmazonSQS.class); sqsQueueResource = new SqsQueueResource(queueName, queueUrl, amazonSqsClient); }
Example #10
Source File: AmazonSQSExtendedClientTest.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 5 votes |
@Test public void testWhenSendMessageWithAlwaysThroughS3AndMessageIsSmallThenItIsStillStoredInS3() { int messageLength = LESS_THAN_SQS_SIZE_LIMIT; String messageBody = generateStringWithLength(messageLength); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withLargePayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withAlwaysThroughS3(true); AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mock(AmazonSQSClient.class), extendedClientConfiguration)); SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); sqsExtended.sendMessage(messageRequest); verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class)); }
Example #11
Source File: AmazonSQSExtendedClientTest.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 5 votes |
@Test public void testWhenSendMessageWithSetMessageSizeThresholdThenThresholdIsHonored() { int messageLength = ARBITRATY_SMALLER_THRESSHOLD * 2; String messageBody = generateStringWithLength(messageLength); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withLargePayloadSupportEnabled(mockS3, S3_BUCKET_NAME).withMessageSizeThreshold(ARBITRATY_SMALLER_THRESSHOLD); AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mock(AmazonSQSClient.class), extendedClientConfiguration)); SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); sqsExtended.sendMessage(messageRequest); verify(mockS3, times(1)).putObject(isA(PutObjectRequest.class)); }
Example #12
Source File: PubSubUtils.java From kork with Apache License 2.0 | 5 votes |
private static String getQueueUrl(AmazonSQS amazonSQS, ARN queueARN) { String queueUrl; try { queueUrl = amazonSQS.getQueueUrl(queueARN.getName()).getQueueUrl(); log.debug("Reusing existing queue {}", queueUrl); } catch (QueueDoesNotExistException e) { queueUrl = amazonSQS.createQueue(queueARN.getName()).getQueueUrl(); log.debug("Created queue {}", queueUrl); } return queueUrl; }
Example #13
Source File: AmazonSQSExtendedClientTest.java From amazon-sqs-java-extended-client-lib with Apache License 2.0 | 5 votes |
@Test public void testWhenSendMessageWithLargePayloadSupportDisabledThenS3IsNotUsedAndSqsBackendIsResponsibleToFailIt() { int messageLength = MORE_THAN_SQS_SIZE_LIMIT; String messageBody = generateStringWithLength(messageLength); ExtendedClientConfiguration extendedClientConfiguration = new ExtendedClientConfiguration() .withLargePayloadSupportDisabled(); AmazonSQS sqsExtended = spy(new AmazonSQSExtendedClient(mockSqsBackend, extendedClientConfiguration)); SendMessageRequest messageRequest = new SendMessageRequest(SQS_QUEUE_URL, messageBody); sqsExtended.sendMessage(messageRequest); verify(mockS3, never()).putObject(isA(PutObjectRequest.class)); verify(mockSqsBackend).sendMessage(eq(messageRequest)); }
Example #14
Source File: SqsOperationsImpl.java From herd with Apache License 2.0 | 5 votes |
@Override public SendMessageResult sendMessage(String queueName, String messageText, Map<String, MessageAttributeValue> messageAttributes, AmazonSQS amazonSQS) { try { return amazonSQS.sendMessage(new SendMessageRequest().withQueueUrl(amazonSQS.getQueueUrl(queueName).getQueueUrl()).withMessageBody(messageText) .withMessageAttributes(messageAttributes)); } catch (QueueDoesNotExistException e) { throw new IllegalStateException(String.format("AWS SQS queue with \"%s\" name not found.", queueName), e); } }
Example #15
Source File: SqsExtractor.java From pocket-etl with Apache License 2.0 | 5 votes |
private SqsExtractor( AmazonSQS amazonSqs, Function<String, T> stringMapper, String queueUrl, Integer batchSizeLimit) { this.amazonSqs = amazonSqs; this.stringMapper = stringMapper; this.queueUrl = queueUrl; this.extractedMessagesReceiptHandle = new ArrayList<>(0); this.batchSizeLimit = (batchSizeLimit == null || batchSizeLimit < 0) ? Integer.MAX_VALUE : batchSizeLimit; }
Example #16
Source File: SQSMessageConsumer.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
SQSMessageConsumer(AmazonSQS sqs, String queueUrl, Consumer<Message> consumer, Runnable shutdownHook, Consumer<Exception> exceptionHandler, int maxWaitTimeSeconds, int pollingThreadCount) { this.sqs = Objects.requireNonNull(sqs); this.queueUrl = Objects.requireNonNull(queueUrl); this.consumer = Objects.requireNonNull(consumer); this.shutdownHook = Objects.requireNonNull(shutdownHook); this.exceptionHandler = Objects.requireNonNull(exceptionHandler); this.maxWaitTimeSeconds = maxWaitTimeSeconds; this.pollingThreadCount = pollingThreadCount; }
Example #17
Source File: AmazonMessageAcknowledger.java From echo with Apache License 2.0 | 5 votes |
public AmazonMessageAcknowledger( AmazonSQS amazonSQS, String queueUrl, Message message, Registry registry, String subscriptionName) { this.amazonSQS = amazonSQS; this.queueUrl = queueUrl; this.message = message; this.registry = registry; this.subscriptionName = subscriptionName; }
Example #18
Source File: AWSSQSLocalContainerService.java From camel-kafka-connector with Apache License 2.0 | 5 votes |
@Override public AWSSQSClient getClient() { AmazonSQS sqs = AmazonSQSClientBuilder .standard() .withEndpointConfiguration(getContainer() .getEndpointConfiguration(LocalStackContainer.Service.SQS)) .withCredentials(getContainer().getDefaultCredentialsProvider()) .build(); return new AWSSQSClient(sqs); }
Example #19
Source File: SQSImpl.java From aws-sdk-java-resources with Apache License 2.0 | 5 votes |
/** * Construct a service implementation using the specified client object. * * @param client The low-level client which the service implementation will * use to make API calls. */ public SQSImpl(AmazonSQS client) { ServiceModel model = V1ModelLoader.load(SQS.class, SQS.class.getAnnotation(V1ServiceInterface.class).model()); this.service = new ServiceImpl<AmazonSQS>(model, client); }
Example #20
Source File: SQSConnectionFactory.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 5 votes |
public SQSConnection createConnection(AWSCredentialsProvider awsCredentialsProvider) throws JMSException { try { AmazonSQS amazonSQS = amazonSQSClientSupplier.get(); return createConnection(amazonSQS, awsCredentialsProvider); } catch(Exception e) { throw (JMSException) new JMSException("Error creating SQS client: " + e.getMessage()).initCause(e); } }
Example #21
Source File: VisibilityTimeout.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
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); }
Example #22
Source File: SQSTriggerQueue.java From aws-codecommit-trigger-plugin with Apache License 2.0 | 5 votes |
public ListBoxModel doFillRegionItems() { ListBoxModel items = new ListBoxModel(); items.add("", ""); for (Regions region : Regions.values()) { Region r = Region.getRegion(region); if (r.isServiceSupported(AmazonSQS.ENDPOINT_PREFIX) && r.isServiceSupported("codecommit")) { items.add(region.getName(), region.name()); } } return items; }
Example #23
Source File: SQSFactoryImpl.java From aws-codecommit-trigger-plugin with Apache License 2.0 | 5 votes |
@Override public AmazonSQS createSQSAsync(final SQSQueue queue) { AWSCredentialsProvider credentials = queue.hasCredentials() ? queue.lookupAwsCredentials() : DefaultAWSCredentialsProviderChain.getInstance(); AmazonSQSAsyncClientBuilder sqsAsyncBuilder = createStandardAsyncClientBuilder(queue, credentials); final QueueBufferConfig queueBufferConfig = this.getQueueBufferConfig(queue); final AmazonSQSBufferedAsyncClient sqsBufferedAsync = new AmazonSQSBufferedAsyncClient(sqsAsyncBuilder.build(), queueBufferConfig); return sqsBufferedAsync; }
Example #24
Source File: AmazonSQSMessagingClientWrapper.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 5 votes |
/** * @param amazonSQSClient * The AWS SDK Client for SQS. * @throws JMSException * if the client is null */ public AmazonSQSMessagingClientWrapper(AmazonSQS amazonSQSClient, AWSCredentialsProvider credentialsProvider) throws JMSException { if (amazonSQSClient == null) { throw new JMSException("Amazon SQS client cannot be null"); } this.amazonSQSClient = amazonSQSClient; this.credentialsProvider = credentialsProvider; }
Example #25
Source File: SQSFactoryImpl.java From aws-codecommit-trigger-plugin with Apache License 2.0 | 5 votes |
public AmazonSQS createSQSAsync(String accessKey, String secretKey, String region) {//TODO check region is Enum? AmazonSQSAsyncClientBuilder sqsAsyncBuilder = createStandardAsyncClientBuilder(null, new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey))); if (StringUtils.isNotBlank(region)) { sqsAsyncBuilder.withRegion(Regions.valueOf(region)); } final QueueBufferConfig queueBufferConfig = this.getQueueBufferConfig(null); final AmazonSQSBufferedAsyncClient sqsBufferedAsync = new AmazonSQSBufferedAsyncClient(sqsAsyncBuilder.build(), queueBufferConfig); return sqsBufferedAsync; }
Example #26
Source File: DynamicQueueUrlDestinationResolverTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Test void testAbsoluteUrl() throws Exception { AmazonSQS amazonSqs = mock(AmazonSQS.class); DynamicQueueUrlDestinationResolver dynamicQueueDestinationResolver = new DynamicQueueUrlDestinationResolver( amazonSqs); String destination = "https://sqs-amazon.aws.com/123123123/myQueue"; assertThat(dynamicQueueDestinationResolver.resolveDestination(destination)) .isEqualTo(destination); }
Example #27
Source File: ScanUploadModule.java From emodb with Apache License 2.0 | 5 votes |
@Inject public SQSScanWorkflowProvider(@ServerCluster String cluster, AmazonSQS amazonSQS, @Named ("pendingScanRangeQueueName") Optional<String> pendingScanRangeQueueName, @Named ("completeScanRangeQueueName") Optional<String> completeScanRangeQueueName) { _amazonSQS = amazonSQS; _pendingScanRangeQueueName = pendingScanRangeQueueName.or(String.format("emodb-pending-scan-ranges-%s", cluster)); _completeScanRangeQueueName = completeScanRangeQueueName.or(String.format("emodb-complete-scan-ranges-%s", cluster)); }
Example #28
Source File: DynamicQueueUrlDestinationResolver.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
public DynamicQueueUrlDestinationResolver(AmazonSQS amazonSqs, ResourceIdResolver resourceIdResolver) { Assert.notNull(amazonSqs, "amazonSqs must not be null"); this.amazonSqs = amazonSqs; this.resourceIdResolver = resourceIdResolver; }
Example #29
Source File: ScanUploadModule.java From emodb with Apache License 2.0 | 5 votes |
@Provides @Singleton protected AmazonSQS provideAmazonSQS(Region region, AWSCredentialsProvider credentialsProvider) { AmazonSQS amazonSQS = new AmazonSQSClient(credentialsProvider); amazonSQS.setRegion(region); return amazonSQS; }
Example #30
Source File: VisibilityTimeout.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
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, 60 * 60); //1 hour // change visibility timeout (multiple) changeMessageVisibilityMultiple(queue_url, 30 * 60 ); //30 minutes }