Package com.softwaremill.common.sqs

Examples of com.softwaremill.common.sqs.Queue


        return sqs;
    }

    @Timeout
    public void timeout(javax.ejb.Timer timer) {
        Queue queue = getSQS().getQueueByName(TASK_SQS_QUEUE);
        Optional<ReceivedMessage> sqsAnswer = queue.receiveSingleMessage();

        if (sqsAnswer.isPresent()) {
            Object message = sqsAnswer.get().getMessage();

            if (message instanceof OneTimeTask) {
                LOG.debug("Deserialized message: " + message);
                OneTimeTask task = (OneTimeTask) message;
                try {
                    if (task.getTaskTimeout() != null) {
                        queue.setMessageVisibilityTimeout(sqsAnswer.get(), task.getTaskTimeout());
                    }

                    new ExecuteWithRequestContext(task).execute();

                    queue.deleteMessage(sqsAnswer.get());
                } catch (RuntimeException e) {
                    LOG.warn("Something went wrong and the task has not been executed. Redelivery will occur.", e);
                }
            } else {
                LOG.warn("Trash in SQS: " + TASK_SQS_QUEUE);
                LOG.warn("Deserialized message: " + message + " -- removing message from queue!");
                queue.deleteMessage(sqsAnswer.get());
            }
        }

        LOG.debug("SQS task queue checked " + TASK_SQS_QUEUE);
    }
View Full Code Here

TOP

Related Classes of com.softwaremill.common.sqs.Queue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.