com.amazonaws.services.sqs.model.AmazonSQSException Java Examples
The following examples show how to use
com.amazonaws.services.sqs.model.AmazonSQSException.
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: IntegrationTest.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 6 votes |
protected AmazonSQS getBuddyPrincipalClient() { AWSCredentialsProvider credentialsProvider = getBuddyCredentials(); AmazonSQS client = AmazonSQSClientBuilder.standard() .withRegion("us-west-2") .withCredentials(credentialsProvider) .build(); // Assume that the principal is not able to send messages to arbitrary queues String queueUrl = sqs.createQueue(queueNamePrefix + "TestQueue").getQueueUrl(); try { client.sendMessage(queueUrl, "Haxxors!!"); assumeTrue("The buddy credentials should not authorize sending to arbitrary queues", false); } catch (AmazonSQSException e) { // Access Denied assumeThat(e.getStatusCode(), equalTo(403)); } finally { sqs.deleteQueue(queueUrl); } return client; }
Example #2
Source File: TestDeleteSQS.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testDeleteException() { runner.setProperty(DeleteSQS.QUEUE_URL, "https://sqs.us-west-2.amazonaws.com/123456789012/test-queue-000000000"); final Map<String, String> ff1Attributes = new HashMap<>(); ff1Attributes.put("filename", "1.txt"); ff1Attributes.put("sqs.receipt.handle", "test-receipt-handle-1"); runner.enqueue("TestMessageBody1", ff1Attributes); Mockito.when(mockSQSClient.deleteMessageBatch(Mockito.any(DeleteMessageBatchRequest.class))) .thenThrow(new AmazonSQSException("TestFail")); runner.assertValid(); runner.run(1); ArgumentCaptor<DeleteMessageBatchRequest> captureDeleteRequest = ArgumentCaptor.forClass(DeleteMessageBatchRequest.class); Mockito.verify(mockSQSClient, Mockito.times(1)).deleteMessageBatch(captureDeleteRequest.capture()); runner.assertAllFlowFilesTransferred(DeleteSQS.REL_FAILURE, 1); }
Example #3
Source File: TestPutSQS.java From nifi with Apache License 2.0 | 6 votes |
@Test public void testPutException() throws IOException { runner.setProperty(PutSQS.QUEUE_URL, "https://sqs.us-west-2.amazonaws.com/123456789012/test-queue-000000000"); final Map<String, String> attrs = new HashMap<>(); attrs.put("filename", "1.txt"); runner.enqueue("TestMessageBody", attrs); Mockito.when(mockSQSClient.sendMessageBatch(Mockito.any(SendMessageBatchRequest.class))).thenThrow(new AmazonSQSException("TestFail")); runner.run(1); ArgumentCaptor<SendMessageBatchRequest> captureRequest = ArgumentCaptor.forClass(SendMessageBatchRequest.class); Mockito.verify(mockSQSClient, Mockito.times(1)).sendMessageBatch(captureRequest.capture()); SendMessageBatchRequest request = captureRequest.getValue(); assertEquals("https://sqs.us-west-2.amazonaws.com/123456789012/test-queue-000000000", request.getQueueUrl()); assertEquals("TestMessageBody", request.getEntries().get(0).getMessageBody()); runner.assertAllFlowFilesTransferred(PutSQS.REL_FAILURE, 1); }
Example #4
Source File: AmazonSQSTemporaryQueuesClientCrossAccountIT.java From amazon-sqs-java-temporary-queues-client with Apache License 2.0 | 5 votes |
@Test public void accessDenied() { // Assert that a different principal is not permitted to // send to virtual queues String virtualQueueUrl = client.createQueue(queueNamePrefix + "TestQueueWithoutAccess").getQueueUrl(); try { otherAccountClient.sendMessage(virtualQueueUrl, "Haxxors!!"); Assert.fail("Should not have been able to send a message"); } catch (AmazonSQSException e) { // Access Denied assertEquals(403, e.getStatusCode()); } finally { client.deleteQueue(virtualQueueUrl); } }
Example #5
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 }
Example #6
Source File: SendReceiveMessages.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
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()); } }
Example #7
Source File: LongPolling.java From aws-doc-sdk-examples with Apache License 2.0 | 4 votes |
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); }