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));
}
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;
}
Aggregations