Search in sources :

Example 1 with Message

use of com.amazonaws.services.sqs.model.Message in project camel by apache.

the class SqsDoesNotExtendMessageVisibilityTest method defaultsToDisabled.

@Test
public void defaultsToDisabled() throws Exception {
    this.mock.expectedMessageCount(1);
    this.mock.whenAnyExchangeReceived(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            // Simulate message that takes a while to receive.
            // 150% of TIMEOUT.
            Thread.sleep(TIMEOUT * 1500L);
        }
    });
    Message message = new Message();
    message.setBody("Message 1");
    message.setMD5OfBody("6a1559560f67c5e7a7d5d838bf0272ee");
    message.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458");
    message.setReceiptHandle(RECEIPT_HANDLE);
    this.clientMock.messages.add(message);
    // Wait for message to arrive.
    assertMockEndpointsSatisfied();
    assertTrue("Expected no changeMessageVisibility requests.", this.clientMock.changeMessageVisibilityRequests.size() == 0);
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(com.amazonaws.services.sqs.model.Message) Test(org.junit.Test)

Example 2 with Message

use of com.amazonaws.services.sqs.model.Message in project camel by apache.

the class SqsExtendMessageVisibilityTest method longReceiveExtendsMessageVisibility.

@Test
public void longReceiveExtendsMessageVisibility() throws Exception {
    this.mock.expectedMessageCount(1);
    this.mock.whenAnyExchangeReceived(new Processor() {

        @Override
        public void process(Exchange exchange) throws Exception {
            // Simulate message that takes a while to receive.
            // 150% of TIMEOUT.
            Thread.sleep(TIMEOUT * 1500L);
        }
    });
    Message message = new Message();
    message.setBody("Message 1");
    message.setMD5OfBody("6a1559560f67c5e7a7d5d838bf0272ee");
    message.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458");
    message.setReceiptHandle(RECEIPT_HANDLE);
    this.clientMock.messages.add(message);
    // Wait for message to arrive.
    assertMockEndpointsSatisfied();
    assertTrue("Expected at least one changeMessageVisibility request.", this.clientMock.changeMessageVisibilityRequests.size() >= 1);
    for (ChangeMessageVisibilityRequest req : this.clientMock.changeMessageVisibilityRequests) {
        assertEquals("https://queue.amazonaws.com/541925086079/MyQueue", req.getQueueUrl());
        assertEquals(RECEIPT_HANDLE, req.getReceiptHandle());
        // Should be 1.5 x TIMEOUT as takes into account the delay period
        Integer expectedTimeout = new Integer(6);
        assertEquals(expectedTimeout, req.getVisibilityTimeout());
    }
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) Message(com.amazonaws.services.sqs.model.Message) ChangeMessageVisibilityRequest(com.amazonaws.services.sqs.model.ChangeMessageVisibilityRequest) Test(org.junit.Test)

Example 3 with Message

use of com.amazonaws.services.sqs.model.Message in project camel by apache.

the class AmazonSQSClientMock method sendMessage.

@Override
public SendMessageResult sendMessage(SendMessageRequest sendMessageRequest) throws AmazonServiceException, AmazonClientException {
    Message message = new Message();
    message.setBody(sendMessageRequest.getMessageBody());
    message.setMD5OfBody("6a1559560f67c5e7a7d5d838bf0272ee");
    message.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458");
    message.setReceiptHandle("0NNAq8PwvXsyZkR6yu4nQ07FGxNmOBWi5zC9+4QMqJZ0DJ3gVOmjI2Gh/oFnb0IeJqy5Zc8kH4JX7GVpfjcEDjaAPSeOkXQZRcaBqt" + "4lOtyfj0kcclVV/zS7aenhfhX5Ixfgz/rHhsJwtCPPvTAdgQFGYrqaHly+etJiawiNPVc=");
    synchronized (messages) {
        messages.add(message);
    }
    SendMessageResult result = new SendMessageResult();
    result.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458");
    result.setMD5OfMessageBody("6a1559560f67c5e7a7d5d838bf0272ee");
    return result;
}
Also used : Message(com.amazonaws.services.sqs.model.Message) SendMessageResult(com.amazonaws.services.sqs.model.SendMessageResult)

Example 4 with Message

use of com.amazonaws.services.sqs.model.Message in project camel by apache.

the class SqsBatchConsumerTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    JndiRegistry registry = super.createRegistry();
    AmazonSQSClientMock clientMock = new AmazonSQSClientMock();
    // add 6 messages, one more we will poll
    for (int counter = 0; counter < 6; counter++) {
        Message message = new Message();
        message.setBody("Message " + counter);
        message.setMD5OfBody("6a1559560f67c5e7a7d5d838bf0272ee");
        message.setMessageId("f6fb6f99-5eb2-4be4-9b15-144774141458");
        message.setReceiptHandle("0NNAq8PwvXsyZkR6yu4nQ07FGxNmOBWi5");
        clientMock.messages.add(message);
    }
    registry.bind("amazonSQSClient", clientMock);
    return registry;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) Message(com.amazonaws.services.sqs.model.Message) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 5 with Message

use of com.amazonaws.services.sqs.model.Message in project camel by apache.

the class SqsConsumer method createExchanges.

protected Queue<Exchange> createExchanges(List<Message> messages) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Received {} messages in this poll", messages.size());
    }
    Queue<Exchange> answer = new LinkedList<Exchange>();
    for (Message message : messages) {
        Exchange exchange = getEndpoint().createExchange(message);
        answer.add(exchange);
    }
    return answer;
}
Also used : Exchange(org.apache.camel.Exchange) Message(com.amazonaws.services.sqs.model.Message) LinkedList(java.util.LinkedList)

Aggregations

Message (com.amazonaws.services.sqs.model.Message)10 Exchange (org.apache.camel.Exchange)3 Processor (org.apache.camel.Processor)2 Test (org.junit.Test)2 AmazonSQS (com.amazonaws.services.sqs.AmazonSQS)1 AmazonSQSException (com.amazonaws.services.sqs.model.AmazonSQSException)1 ChangeMessageVisibilityRequest (com.amazonaws.services.sqs.model.ChangeMessageVisibilityRequest)1 CreateQueueResult (com.amazonaws.services.sqs.model.CreateQueueResult)1 ReceiveMessageRequest (com.amazonaws.services.sqs.model.ReceiveMessageRequest)1 ReceiveMessageResult (com.amazonaws.services.sqs.model.ReceiveMessageResult)1 SendMessageBatchRequest (com.amazonaws.services.sqs.model.SendMessageBatchRequest)1 SendMessageBatchRequestEntry (com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry)1 SendMessageRequest (com.amazonaws.services.sqs.model.SendMessageRequest)1 SendMessageResult (com.amazonaws.services.sqs.model.SendMessageResult)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 JndiRegistry (org.apache.camel.impl.JndiRegistry)1