Search in sources :

Example 1 with DeleteMessageRequest

use of com.amazonaws.services.sqs.model.DeleteMessageRequest in project thingsboard by thingsboard.

the class SqsDemoClient method pollMessages.

private void pollMessages(AmazonSQS sqs) {
    log.info("Polling messages");
    while (true) {
        List<Message> messages = sqs.receiveMessage(QUEUE_URL).getMessages();
        messages.forEach(m -> {
            log.info("Message Received: " + m.getBody());
            System.out.println(m.getBody());
            DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest(QUEUE_URL, m.getReceiptHandle());
            sqs.deleteMessage(deleteMessageRequest);
        });
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            e.printStackTrace();
        }
    }
}
Also used : Message(com.amazonaws.services.sqs.model.Message) DeleteMessageRequest(com.amazonaws.services.sqs.model.DeleteMessageRequest)

Example 2 with DeleteMessageRequest

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

the class SqsConsumer method processCommit.

/**
     * Strategy to delete the message after being processed.
     *
     * @param exchange the exchange
     */
protected void processCommit(Exchange exchange) {
    try {
        if (shouldDelete(exchange)) {
            String receiptHandle = exchange.getIn().getHeader(SqsConstants.RECEIPT_HANDLE, String.class);
            DeleteMessageRequest deleteRequest = new DeleteMessageRequest(getQueueUrl(), receiptHandle);
            LOG.trace("Deleting message with receipt handle {}...", receiptHandle);
            getClient().deleteMessage(deleteRequest);
            LOG.trace("Deleted message with receipt handle {}...", receiptHandle);
        }
    } catch (AmazonClientException e) {
        getExceptionHandler().handleException("Error occurred during deleting message. This exception is ignored.", exchange, e);
    }
}
Also used : AmazonClientException(com.amazonaws.AmazonClientException) DeleteMessageRequest(com.amazonaws.services.sqs.model.DeleteMessageRequest)

Aggregations

DeleteMessageRequest (com.amazonaws.services.sqs.model.DeleteMessageRequest)2 AmazonClientException (com.amazonaws.AmazonClientException)1 Message (com.amazonaws.services.sqs.model.Message)1