com.amazonaws.services.sqs.model.QueueDoesNotExistException Java Examples
The following examples show how to use
com.amazonaws.services.sqs.model.QueueDoesNotExistException.
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: AmazonSQSResponderClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 7 votes |
@Override public void sendResponseMessage(MessageContent request, MessageContent response) { MessageAttributeValue attribute = request.getMessageAttributes().get(AmazonSQSRequesterClient.RESPONSE_QUEUE_URL_ATTRIBUTE_NAME); if (attribute != null) { String replyQueueUrl = attribute.getStringValue(); try { SendMessageRequest responseRequest = response.toSendMessageRequest() .withQueueUrl(replyQueueUrl); sqs.sendMessage(responseRequest); } catch (QueueDoesNotExistException e) { // Stale request, ignore // TODO-RS: CW metric LOG.warn("Ignoring response to deleted response queue: " + replyQueueUrl); } } else { // TODO-RS: CW metric LOG.warn("Attempted to send response when none was requested"); } }
Example #2
Source File: AmazonSQSIdleQueueDeletingClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
@Override public DeleteMessageBatchResult deleteMessageBatch(DeleteMessageBatchRequest request) { String queueUrl = request.getQueueUrl(); try { heartbeatToQueueIfNecessary(queueUrl); return super.deleteMessageBatch(request); } catch (QueueDoesNotExistException e) { try { return super.deleteMessageBatch( request.clone().withQueueUrl(alternateQueueName(request.getQueueUrl()))); } catch (QueueDoesNotExistException e2) { // Silently fail - the message is definitely deleted after all! return new DeleteMessageBatchResult(); } } }
Example #3
Source File: IntegrationTest.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
@After public void teardownSQSClient() { if (sqs != null) { // Best effort cleanup of queues. To be complete, we'd have to wait a minute // for the eventual consistency of listQueues() sqs.listQueues(queueNamePrefix).getQueueUrls().forEach(queueUrl -> { try { sqs.deleteQueue(queueUrl); } catch (QueueDoesNotExistException e) { // Ignore } }); sqs.shutdown(); } exceptionHandler.assertNothingThrown(); }
Example #4
Source File: AmazonSQSIdleQueueDeletingIT.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
@After public void teardown() { if (client != null && queueUrl != null) { try { client.deleteQueue(queueUrl); } catch (QueueDoesNotExistException e) { // Ignore } } if (responder != null) { responder.shutdown(); } if (requester != null) { requester.shutdown(); } if (client != null) { client.teardown(); } }
Example #5
Source File: AmazonSQSIdleQueueDeletingClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
@Override public DeleteMessageResult deleteMessage(DeleteMessageRequest request) { String queueUrl = request.getQueueUrl(); try { heartbeatToQueueIfNecessary(queueUrl); return super.deleteMessage(request); } catch (QueueDoesNotExistException|ReceiptHandleIsInvalidException e) { try { return super.deleteMessage( request.clone().withQueueUrl(alternateQueueName(request.getQueueUrl()))); } catch (QueueDoesNotExistException e2) { // Silently fail - the message is definitely deleted after all! return new DeleteMessageResult(); } } }
Example #6
Source File: DynamicQueueUrlDestinationResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void testInvalidDestinationName() throws Exception { AmazonSQS amazonSqs = mock(AmazonSQS.class); AmazonServiceException exception = new QueueDoesNotExistException( "AWS.SimpleQueueService.NonExistentQueue"); exception.setErrorCode("AWS.SimpleQueueService.NonExistentQueue"); String queueUrl = "invalidName"; when(amazonSqs.getQueueUrl(new GetQueueUrlRequest(queueUrl))) .thenThrow(exception); DynamicQueueUrlDestinationResolver dynamicQueueDestinationResolver = new DynamicQueueUrlDestinationResolver( amazonSqs); try { dynamicQueueDestinationResolver.resolveDestination(queueUrl); } catch (DestinationResolutionException e) { assertThat(e.getMessage()).startsWith("The queue does not exist."); } }
Example #7
Source File: DynamicQueueUrlDestinationResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void testPotentiallyNoAccessToPerformGetQueueUrl() throws Exception { AmazonSQS amazonSqs = mock(AmazonSQS.class); AmazonServiceException exception = new QueueDoesNotExistException( "AWS.SimpleQueueService.NonExistentQueue"); exception.setErrorCode("AWS.SimpleQueueService.NonExistentQueue"); exception.setErrorMessage( "The specified queue does not exist or you do not have access to it."); String queueUrl = "noAccessGetQueueUrlName"; when(amazonSqs.getQueueUrl(new GetQueueUrlRequest(queueUrl))) .thenThrow(exception); DynamicQueueUrlDestinationResolver dynamicQueueDestinationResolver = new DynamicQueueUrlDestinationResolver( amazonSqs); try { dynamicQueueDestinationResolver.resolveDestination(queueUrl); } catch (DestinationResolutionException e) { assertThat(e.getMessage()).startsWith( "The queue does not exist or no access to perform action sqs:GetQueueUrl."); } }
Example #8
Source File: AmazonSQSIdleQueueDeletingClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
@Override public ReceiveMessageResult receiveMessage(ReceiveMessageRequest request) { // Here we have to also fetch from the backup queue if we created it. String queueUrl = request.getQueueUrl(); String alternateQueueUrl = alternateQueueName(queueUrl); QueueMetadata alternateMetadata = queues.get(alternateQueueUrl); if (alternateMetadata != null) { ReceiveQueueBuffer buffer = alternateMetadata.buffer; ReceiveMessageRequest alternateRequest = request.clone().withQueueUrl(alternateQueueUrl); buffer.submit(executor, () -> receiveIgnoringNonExistantQueue(request), queueUrl, request.getVisibilityTimeout()); buffer.submit(executor, () -> receiveIgnoringNonExistantQueue(alternateRequest), queueUrl, request.getVisibilityTimeout()); Future<ReceiveMessageResult> receiveFuture = buffer.receiveMessageAsync(request); return SQSQueueUtils.waitForFuture(receiveFuture); } else { try { heartbeatToQueueIfNecessary(queueUrl); return super.receiveMessage(request); } catch (QueueDoesNotExistException e) { request.setQueueUrl(recreateQueue(queueUrl)); return super.receiveMessage(request); } } }
Example #9
Source File: DynamicQueueUrlDestinationResolver.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
private DestinationResolutionException toDestinationResolutionException( QueueDoesNotExistException e) { if (e.getMessage() != null && e.getMessage().contains("access")) { return new DestinationResolutionException( "The queue does not exist or no access to perform action sqs:GetQueueUrl.", e); } else { return new DestinationResolutionException("The queue does not exist.", e); } }
Example #10
Source File: SQSExecutorServiceIT.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
@Test public void listQueuesLimitWorkaround() throws InterruptedException { String prefix = queueNamePrefix + "-listQueuesLimitWorkaround-"; int numQueues = 50; Set<String> expected = new HashSet<>(); for (int i = 0; i < numQueues; i++) { String queueName = prefix + i; expected.add(sqs.createQueue(queueName).getQueueUrl()); } try { SQSQueueUtils.awaitWithPolling(5, 70, TimeUnit.SECONDS, () -> sqs.listQueues(prefix).getQueueUrls().size() == numQueues); List<SQSExecutorService> executors = IntStream.range(0, 5) .mapToObj(x -> createExecutor(queueUrl)) .collect(Collectors.toList()); try (SerializableReference<AmazonSQS> sqsRef = new SerializableReference<>("SQS", sqs, true)) { Function<String, List<String>> lister = SQSExecutorServiceIT.listQueuesFunction(sqsRef); Set<String> allQueueUrls = new HashSet<>(SQSQueueUtils.listQueues(executors.get(0), lister, prefix, 50)); assertEquals(expected.size(), allQueueUrls.size()); assertEquals(expected, allQueueUrls); } } finally { expected.parallelStream().forEach(queueUrl -> { try { sqs.deleteQueue(queueUrl); } catch (QueueDoesNotExistException e) { // Ignore } }); } }
Example #11
Source File: DynamicQueueUrlDestinationResolver.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Override public String resolveDestination(String name) throws DestinationResolutionException { String queueName = name; if (this.resourceIdResolver != null) { queueName = this.resourceIdResolver.resolveToPhysicalResourceId(name); } if (isValidQueueUrl(queueName)) { return queueName; } if (this.autoCreate) { // Auto-create is fine to be called even if the queue exists. CreateQueueResult createQueueResult = this.amazonSqs .createQueue(new CreateQueueRequest(queueName)); return createQueueResult.getQueueUrl(); } else { try { GetQueueUrlResult getQueueUrlResult = this.amazonSqs .getQueueUrl(new GetQueueUrlRequest(queueName)); return getQueueUrlResult.getQueueUrl(); } catch (QueueDoesNotExistException e) { throw toDestinationResolutionException(e); } } }
Example #12
Source File: AmazonSQSMessagingClientWrapperTest.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 5 votes |
@Test(expected = InvalidDestinationException.class) public void testGetQueueUrlQueueNameThrowQueueDoesNotExistException() throws JMSException { GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(QUEUE_NAME); doThrow(new QueueDoesNotExistException("qdnee")) .when(amazonSQSClient).getQueueUrl(eq(getQueueUrlRequest)); wrapper.getQueueUrl(QUEUE_NAME); }
Example #13
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 #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: SQSScanWorkflow.java From emodb with Apache License 2.0 | 5 votes |
private String queryQueueUrl(String queueName) { try { return _sqs.getQueueUrl(new GetQueueUrlRequest(queueName)).getQueueUrl(); } catch (QueueDoesNotExistException e) { // Create the queue int visibilityTimeout = queueName.equals(_pendingScanRangeQueue) ? DEFAULT_TASK_CLAIM_VISIBILITY_TIMEOUT : DEFAULT_TASK_COMPLETE_VISIBILITY_TIMEOUT; return _sqs.createQueue( new CreateQueueRequest(queueName) .withAttributes(ImmutableMap.<String, String>of( "VisibilityTimeout", String.valueOf(visibilityTimeout))) ).getQueueUrl(); } }
Example #16
Source File: AmazonSQSMessagingClientWrapperTest.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 5 votes |
@Test(expected = InvalidDestinationException.class) public void testGetQueueUrlQueueNameWithAccountIdThrowQueueDoesNotExistException() throws JMSException { GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(QUEUE_NAME); getQueueUrlRequest.setQueueOwnerAWSAccountId(OWNER_ACCOUNT_ID); doThrow(new QueueDoesNotExistException("qdnee")) .when(amazonSQSClient).getQueueUrl(eq(getQueueUrlRequest)); wrapper.getQueueUrl(QUEUE_NAME,OWNER_ACCOUNT_ID); }
Example #17
Source File: MockSQS.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
public MockSQSQueue getQueue(String queueUrl) { if (!queueUrl.startsWith(accountPrefix)) { throw new IllegalArgumentException(); } else { String queueName = queueUrl.substring(accountPrefix.length()); MockSQSQueue queue = queues.get(queueName); if (queue == null) { throw new QueueDoesNotExistException("The queue does not exist"); } return queue; } }
Example #18
Source File: AmazonSQSMessagingClientWrapperTest.java From amazon-sqs-java-messaging-lib with Apache License 2.0 | 5 votes |
@Test public void testQueueExistsThrowQueueDoesNotExistException() throws JMSException { GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(QUEUE_NAME); doThrow(new QueueDoesNotExistException("qdnee")) .when(amazonSQSClient).getQueueUrl(eq(getQueueUrlRequest)); assertFalse(wrapper.queueExists(QUEUE_NAME)); }
Example #19
Source File: IdleQueueSweeper.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
protected void checkQueueForIdleness(String queueUrl) { try { if (isQueueIdle(queueUrl) && SQSQueueUtils.isQueueEmpty(sqs, queueUrl)) { LOG.info("Deleting idle queue: " + queueUrl); sqs.deleteQueue(queueUrl); } } catch (QueueDoesNotExistException e) { // Queue already deleted so nothing to do. } }
Example #20
Source File: AmazonSQSVirtualQueuesClientIT.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
@Test public void expiringVirtualQueue() throws InterruptedException { CreateQueueRequest request = new CreateQueueRequest() .withQueueName("ShortLived") .addAttributesEntry(AmazonSQSVirtualQueuesClient.VIRTUAL_QUEUE_HOST_QUEUE_ATTRIBUTE, hostQueueUrl) .addAttributesEntry(AmazonSQSIdleQueueDeletingClient.IDLE_QUEUE_RETENTION_PERIOD, "10"); String virtualQueueUrl = client.createQueue(request).getQueueUrl(); // Do a few long poll receives and validate the queue stays alive. // We expect empty receives but not errors. ReceiveMessageRequest receiveRequest = new ReceiveMessageRequest() .withQueueUrl(virtualQueueUrl) .withWaitTimeSeconds(5); for (int i = 0; i < 3; i++) { assertEquals(0, client.receiveMessage(receiveRequest).getMessages().size()); } // Now go idle for a while and the queue should be deleted. TimeUnit.SECONDS.sleep(12); try { client.receiveMessage(virtualQueueUrl); fail("Expected queue to be automatically deleted: " + virtualQueueUrl); } catch (QueueDoesNotExistException e) { // Expected } }
Example #21
Source File: SQSQueueUtils.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
public static boolean doesQueueExist(AmazonSQS sqs, String queueUrl) { try { sqs.listQueueTags(queueUrl); return true; } catch (QueueDoesNotExistException e) { return false; } }
Example #22
Source File: AmazonSQSVirtualQueuesClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
private Optional<VirtualQueue> getVirtualQueue(String queueUrl) { Optional<VirtualQueueID> optionalVirtualQueueId = VirtualQueueID.fromQueueUrl(queueUrl); if (optionalVirtualQueueId.isPresent()) { VirtualQueueID virtualQueueId = optionalVirtualQueueId.get(); Optional<VirtualQueue> result = Optional.ofNullable(virtualQueues.get(virtualQueueId.getVirtualQueueName())); if (!result.isPresent()) { throw new QueueDoesNotExistException("The specified queue does not exist"); } return result; } else { return Optional.empty(); } }
Example #23
Source File: AmazonSQSIdleQueueDeletingClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
@Override public ChangeMessageVisibilityBatchResult changeMessageVisibilityBatch(ChangeMessageVisibilityBatchRequest request) { // If the queue is deleted, there's no way to change the message visibility. try { return super.changeMessageVisibilityBatch(request); } catch (QueueDoesNotExistException|ReceiptHandleIsInvalidException e) { // Try on the alternate queue ChangeMessageVisibilityBatchRequest alternateRequest = request.clone().withQueueUrl(alternateQueueName(request.getQueueUrl())); return super.changeMessageVisibilityBatch(alternateRequest); } }
Example #24
Source File: AmazonSQSIdleQueueDeletingClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
@Override public ChangeMessageVisibilityResult changeMessageVisibility(ChangeMessageVisibilityRequest request) { // If the queue is deleted, there's no way to change the message visibility. try { return super.changeMessageVisibility(request); } catch (QueueDoesNotExistException|ReceiptHandleIsInvalidException e) { // Try on the alternate queue return super.changeMessageVisibility( request.clone().withQueueUrl(alternateQueueName(request.getQueueUrl()))); } }
Example #25
Source File: AmazonSQSIdleQueueDeletingClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
private List<Message> receiveIgnoringNonExistantQueue(ReceiveMessageRequest request) { try { heartbeatToQueueIfNecessary(request.getQueueUrl()); return amazonSqsToBeExtended.receiveMessage(request).getMessages(); } catch (QueueDoesNotExistException e) { return Collections.emptyList(); } }
Example #26
Source File: AmazonSQSIdleQueueDeletingClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
@Override public SendMessageBatchResult sendMessageBatch(SendMessageBatchRequest request) { try { heartbeatToQueueIfNecessary(request.getQueueUrl()); return super.sendMessageBatch(request); } catch (QueueDoesNotExistException e) { request.setQueueUrl(recreateQueue(request.getQueueUrl())); return super.sendMessageBatch(request); } }
Example #27
Source File: AmazonSQSIdleQueueDeletingClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
@Override public SendMessageResult sendMessage(SendMessageRequest request) { try { heartbeatToQueueIfNecessary(request.getQueueUrl()); return super.sendMessage(request); } catch (QueueDoesNotExistException e) { request.setQueueUrl(recreateQueue(request.getQueueUrl())); return super.sendMessage(request); } }
Example #28
Source File: AmazonSQSIdleQueueDeletingClient.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
private void heartbeatToQueue(String queueUrl) { // TODO-RS: Clock drift? Shouldn't realistically be a problem as long as the idleness threshold is long enough. long currentTimestamp = System.currentTimeMillis(); try { amazonSqsToBeExtended.tagQueue(queueUrl, Collections.singletonMap(LAST_HEARTBEAT_TIMESTAMP_TAG, String.valueOf(currentTimestamp))); } catch (QueueDoesNotExistException e) { recreateQueue(queueUrl); // TODO-RS: Retry right away } queues.get(queueUrl).heartbeatTimestamp = currentTimestamp; }
Example #29
Source File: AmazonSQSIdleQueueDeletingIT.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 4 votes |
@Test public void recreatingQueues() throws InterruptedException { String queueName = queueNamePrefix + "-DeletedTooSoon"; CreateQueueRequest createQueueRequest = new CreateQueueRequest() .withQueueName(queueName) .addAttributesEntry(AmazonSQSIdleQueueDeletingClient.IDLE_QUEUE_RETENTION_PERIOD, "60"); queueUrl = client.createQueue(createQueueRequest).getQueueUrl(); QueueUser user = new QueueUser(); user.start(); TimeUnit.SECONDS.sleep(5); // Use the underlying client so the wrapper has no chance to do anything first sqs.deleteQueue(queueUrl); // Sleeping is unfortunate here, but it's necessary to ensure the eventual consistency // of the delete is resolved first. Otherwise it's easy to get a false positive below. TimeUnit.MINUTES.sleep(1); // Ensure the original queue is eventually recreated. This becoming true at least once // indicates that CreateQueue was successfully called, even if it may flip back to false // on subsequent calls. Assert.assertTrue("Expected original queue to be recreated: " + queueUrl, SQSQueueUtils.awaitQueueCreated(sqs, queueUrl, 70, TimeUnit.SECONDS)); // Ensure the user doesn't experience any send or receive failures user.finish(); String failoverQueueName = AmazonSQSIdleQueueDeletingClient.alternateQueueName(queueName); String failoverQueueUrl = sqs.getQueueUrl(failoverQueueName).getQueueUrl(); // Delete the queue through the client and ensure the failover queue is also deleted. // Eventual consistency is a problem here as well - the DeleteQueue may fail if // done too soon after recreating a queue. SQSQueueUtils.awaitWithPolling(2, 70, TimeUnit.SECONDS, () -> { try { client.deleteQueue(queueUrl); return true; } catch (QueueDoesNotExistException e) { return false; } }); Assert.assertTrue("Expected original queue to be deleted: " + failoverQueueUrl, SQSQueueUtils.awaitQueueDeleted(sqs, queueUrl, 70, TimeUnit.SECONDS)); Assert.assertTrue("Expected failover queue to be deleted with the original: " + failoverQueueUrl, SQSQueueUtils.awaitQueueDeleted(sqs, failoverQueueUrl, 70, TimeUnit.SECONDS)); }