Search in sources :

Example 1 with ReceiveMessageResult

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

the class SqsConsumer method poll.

@Override
protected int poll() throws Exception {
    // must reset for each poll
    shutdownRunningTask = null;
    pendingExchanges = 0;
    ReceiveMessageRequest request = new ReceiveMessageRequest(getQueueUrl());
    request.setMaxNumberOfMessages(getMaxMessagesPerPoll() > 0 ? getMaxMessagesPerPoll() : null);
    request.setVisibilityTimeout(getConfiguration().getVisibilityTimeout() != null ? getConfiguration().getVisibilityTimeout() : null);
    request.setWaitTimeSeconds(getConfiguration().getWaitTimeSeconds() != null ? getConfiguration().getWaitTimeSeconds() : null);
    if (attributeNames != null) {
        request.setAttributeNames(attributeNames);
    }
    if (messageAttributeNames != null) {
        request.setMessageAttributeNames(messageAttributeNames);
    }
    LOG.trace("Receiving messages with request [{}]...", request);
    ReceiveMessageResult messageResult = null;
    try {
        messageResult = getClient().receiveMessage(request);
    } catch (QueueDoesNotExistException e) {
        LOG.info("Queue does not exist....recreating now...");
        reConnectToQueue();
        messageResult = getClient().receiveMessage(request);
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("Received {} messages", messageResult.getMessages().size());
    }
    Queue<Exchange> exchanges = createExchanges(messageResult.getMessages());
    return processBatch(CastUtils.cast(exchanges));
}
Also used : QueueDoesNotExistException(com.amazonaws.services.sqs.model.QueueDoesNotExistException) Exchange(org.apache.camel.Exchange) ReceiveMessageRequest(com.amazonaws.services.sqs.model.ReceiveMessageRequest) ReceiveMessageResult(com.amazonaws.services.sqs.model.ReceiveMessageResult)

Example 2 with ReceiveMessageResult

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

the class AmazonSQSClientMock method receiveMessage.

@Override
public ReceiveMessageResult receiveMessage(ReceiveMessageRequest receiveMessageRequest) throws AmazonServiceException, AmazonClientException {
    Integer maxNumberOfMessages = receiveMessageRequest.getMaxNumberOfMessages() != null ? receiveMessageRequest.getMaxNumberOfMessages() : Integer.MAX_VALUE;
    ReceiveMessageResult result = new ReceiveMessageResult();
    Collection<Message> resultMessages = new ArrayList<Message>();
    synchronized (messages) {
        int fetchSize = 0;
        for (Iterator<Message> iterator = messages.iterator(); iterator.hasNext() && fetchSize < maxNumberOfMessages; fetchSize++) {
            Message rc = iterator.next();
            resultMessages.add(rc);
            iterator.remove();
            scheduleCancelInflight(receiveMessageRequest.getQueueUrl(), rc);
        }
    }
    result.setMessages(resultMessages);
    return result;
}
Also used : Message(com.amazonaws.services.sqs.model.Message) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ReceiveMessageResult(com.amazonaws.services.sqs.model.ReceiveMessageResult)

Aggregations

ReceiveMessageResult (com.amazonaws.services.sqs.model.ReceiveMessageResult)2 Message (com.amazonaws.services.sqs.model.Message)1 QueueDoesNotExistException (com.amazonaws.services.sqs.model.QueueDoesNotExistException)1 ReceiveMessageRequest (com.amazonaws.services.sqs.model.ReceiveMessageRequest)1 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Exchange (org.apache.camel.Exchange)1