Search in sources :

Example 11 with ReceiveMessageRequest

use of com.amazonaws.services.sqs.model.ReceiveMessageRequest in project nifi by apache.

the class TestGetSQS method testGetNoMessages.

@Test
public void testGetNoMessages() {
    runner.setProperty(GetSQS.QUEUE_URL, "https://sqs.us-west-2.amazonaws.com/123456789012/test-queue-000000000");
    ReceiveMessageResult receiveMessageResult = new ReceiveMessageResult();
    Mockito.when(mockSQSClient.receiveMessage(Mockito.any(ReceiveMessageRequest.class))).thenReturn(receiveMessageResult);
    runner.run(1);
    ArgumentCaptor<ReceiveMessageRequest> captureRequest = ArgumentCaptor.forClass(ReceiveMessageRequest.class);
    Mockito.verify(mockSQSClient, Mockito.times(1)).receiveMessage(captureRequest.capture());
    ReceiveMessageRequest request = captureRequest.getValue();
    assertEquals("https://sqs.us-west-2.amazonaws.com/123456789012/test-queue-000000000", request.getQueueUrl());
    runner.assertAllFlowFilesTransferred(GetSQS.REL_SUCCESS, 0);
}
Also used : ReceiveMessageRequest(com.amazonaws.services.sqs.model.ReceiveMessageRequest) ReceiveMessageResult(com.amazonaws.services.sqs.model.ReceiveMessageResult) Test(org.junit.Test)

Example 12 with ReceiveMessageRequest

use of com.amazonaws.services.sqs.model.ReceiveMessageRequest in project glacier-cli by carlossg.

the class Glacier method waitForJobToComplete.

private Boolean waitForJobToComplete(String jobId, String sqsQueueUrl) throws InterruptedException, JsonParseException, IOException {
    Boolean messageFound = false;
    Boolean jobSuccessful = false;
    ObjectMapper mapper = new ObjectMapper();
    JsonFactory factory = mapper.getJsonFactory();
    Date start = new Date();
    while (!messageFound) {
        long minutes = (new Date().getTime() - start.getTime()) / 1000 / 60;
        System.out.println("Checking for messages: " + minutes + " elapsed");
        List<Message> msgs = sqsClient.receiveMessage(new ReceiveMessageRequest(sqsQueueUrl).withMaxNumberOfMessages(10)).getMessages();
        if (msgs.size() > 0) {
            for (Message m : msgs) {
                JsonParser jpMessage = factory.createJsonParser(m.getBody());
                JsonNode jobMessageNode = mapper.readTree(jpMessage);
                String jobMessage = jobMessageNode.get("Message").getTextValue();
                JsonParser jpDesc = factory.createJsonParser(jobMessage);
                JsonNode jobDescNode = mapper.readTree(jpDesc);
                String retrievedJobId = jobDescNode.get("JobId").getTextValue();
                String statusCode = jobDescNode.get("StatusCode").getTextValue();
                if (retrievedJobId.equals(jobId)) {
                    messageFound = true;
                    if (statusCode.equals("Succeeded")) {
                        jobSuccessful = true;
                    }
                }
            }
        } else {
            Thread.sleep(sleepTime * 1000);
        }
    }
    return (messageFound && jobSuccessful);
}
Also used : Message(com.amazonaws.services.sqs.model.Message) ReceiveMessageRequest(com.amazonaws.services.sqs.model.ReceiveMessageRequest) JsonFactory(org.codehaus.jackson.JsonFactory) JsonNode(org.codehaus.jackson.JsonNode) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Date(java.util.Date) JsonParser(org.codehaus.jackson.JsonParser)

Example 13 with ReceiveMessageRequest

use of com.amazonaws.services.sqs.model.ReceiveMessageRequest in project java by wavefrontHQ.

the class SQSSubmissionQueueTest method testTaskRead.

@Test
public void testTaskRead() throws IOException {
    SQSSubmissionQueue queue = getTaskQueue();
    UUID proxyId = UUID.randomUUID();
    DataSubmissionTask<? extends DataSubmissionTask<?>> task;
    if (this.expectedTask instanceof LineDelimitedDataSubmissionTask) {
        task = new LineDelimitedDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "wavefront", ReportableEntityType.POINT, "2878", ImmutableList.of("item1", "item2", "item3"), time::get);
    } else if (this.expectedTask instanceof EventDataSubmissionTask) {
        task = new EventDataSubmissionTask(null, proxyId, new DefaultEntityPropertiesForTesting(), queue, "2878", ImmutableList.of(new Event(ReportEvent.newBuilder().setStartTime(time.get() * 1000).setEndTime(time.get() * 1000 + 1).setName("Event name for testing").setHosts(ImmutableList.of("host1", "host2")).setDimensions(ImmutableMap.of("multi", ImmutableList.of("bar", "baz"))).setAnnotations(ImmutableMap.of("severity", "INFO")).setTags(ImmutableList.of("tag1")).build())), time::get);
    } else {
        task = null;
    }
    expect(client.sendMessage(new SendMessageRequest(queueUrl, queue.encodeMessageForDelivery(this.expectedTask)))).andReturn(null);
    replay(client);
    task.enqueue(QueueingReason.RETRY);
    reset(client);
    ReceiveMessageRequest msgRequest = new ReceiveMessageRequest().withMaxNumberOfMessages(1).withWaitTimeSeconds(1).withQueueUrl(queueUrl);
    ReceiveMessageResult msgResult = new ReceiveMessageResult().withMessages(new Message().withBody(queue.encodeMessageForDelivery(task)).withReceiptHandle("handle1"));
    expect(client.receiveMessage(msgRequest)).andReturn(msgResult);
    replay(client);
    if (this.expectedTask instanceof LineDelimitedDataSubmissionTask) {
        LineDelimitedDataSubmissionTask readTask = (LineDelimitedDataSubmissionTask) queue.peek();
        assertEquals(((LineDelimitedDataSubmissionTask) task).payload(), readTask.payload());
        assertEquals(((LineDelimitedDataSubmissionTask) this.expectedTask).payload(), readTask.payload());
        assertEquals(77777, readTask.getEnqueuedMillis());
    }
    if (this.expectedTask instanceof EventDataSubmissionTask) {
        EventDataSubmissionTask readTask = (EventDataSubmissionTask) queue.peek();
        assertEquals(((EventDataSubmissionTask) task).payload(), readTask.payload());
        assertEquals(((EventDataSubmissionTask) this.expectedTask).payload(), readTask.payload());
        assertEquals(77777, readTask.getEnqueuedMillis());
    }
}
Also used : ReceiveMessageRequest(com.amazonaws.services.sqs.model.ReceiveMessageRequest) Message(com.amazonaws.services.sqs.model.Message) EventDataSubmissionTask(com.wavefront.agent.data.EventDataSubmissionTask) ReportEvent(wavefront.report.ReportEvent) Event(com.wavefront.dto.Event) LineDelimitedDataSubmissionTask(com.wavefront.agent.data.LineDelimitedDataSubmissionTask) DefaultEntityPropertiesForTesting(com.wavefront.agent.data.DefaultEntityPropertiesForTesting) UUID(java.util.UUID) SendMessageRequest(com.amazonaws.services.sqs.model.SendMessageRequest) ReceiveMessageResult(com.amazonaws.services.sqs.model.ReceiveMessageResult) Test(org.junit.Test)

Aggregations

ReceiveMessageRequest (com.amazonaws.services.sqs.model.ReceiveMessageRequest)13 ReceiveMessageResult (com.amazonaws.services.sqs.model.ReceiveMessageResult)11 Message (com.amazonaws.services.sqs.model.Message)8 Test (org.junit.Test)6 DeleteMessageBatchRequest (com.amazonaws.services.sqs.model.DeleteMessageBatchRequest)4 AmazonSQS (com.amazonaws.services.sqs.AmazonSQS)3 MessageAttributeValue (com.amazonaws.services.sqs.model.MessageAttributeValue)3 AmazonSQSClient (com.amazonaws.services.sqs.AmazonSQSClient)2 DeleteMessageBatchRequestEntry (com.amazonaws.services.sqs.model.DeleteMessageBatchRequestEntry)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MockFlowFile (org.apache.nifi.util.MockFlowFile)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 TransportException (co.krypt.krypton.exception.TransportException)1 NetworkMessage (co.krypt.krypton.protocol.NetworkMessage)1 AmazonClientException (com.amazonaws.AmazonClientException)1 AmazonSQSException (com.amazonaws.services.sqs.model.AmazonSQSException)1 CreateQueueRequest (com.amazonaws.services.sqs.model.CreateQueueRequest)1 QueueDoesNotExistException (com.amazonaws.services.sqs.model.QueueDoesNotExistException)1 SendMessageRequest (com.amazonaws.services.sqs.model.SendMessageRequest)1