Search in sources :

Example 1 with QueueDoesNotExistException

use of com.amazonaws.services.sqs.model.QueueDoesNotExistException 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)

Aggregations

QueueDoesNotExistException (com.amazonaws.services.sqs.model.QueueDoesNotExistException)1 ReceiveMessageRequest (com.amazonaws.services.sqs.model.ReceiveMessageRequest)1 ReceiveMessageResult (com.amazonaws.services.sqs.model.ReceiveMessageResult)1 Exchange (org.apache.camel.Exchange)1