Example usage for org.springframework.amqp AmqpRejectAndDontRequeueException AmqpRejectAndDontRequeueException

List of usage examples for org.springframework.amqp AmqpRejectAndDontRequeueException AmqpRejectAndDontRequeueException

Introduction

In this page you can find the example usage for org.springframework.amqp AmqpRejectAndDontRequeueException AmqpRejectAndDontRequeueException.

Prototype

public AmqpRejectAndDontRequeueException(String message, Throwable cause) 

Source Link

Usage

From source file:org.eclipse.hawkbit.amqp.AmqpMessageHandlerService.java

/**
 * * Executed if a amqp message arrives.
 * //from   ww w . j a  v a 2s  .co  m
 * @param message
 *            the message
 * @param type
 *            the type
 * @param tenant
 *            the tenant
 * @param virtualHost
 *            the virtual host
 * @return the rpc message back to supplier.
 */
public Message onMessage(final Message message, final String type, final String tenant,
        final String virtualHost) {
    checkContentTypeJson(message);
    final SecurityContext oldContext = SecurityContextHolder.getContext();
    try {
        final MessageType messageType = MessageType.valueOf(type);
        switch (messageType) {
        case THING_CREATED:
            setTenantSecurityContext(tenant);
            registerTarget(message, virtualHost);
            break;
        case EVENT:
            setTenantSecurityContext(tenant);
            final String topicValue = getStringHeaderKey(message, MessageHeaderKey.TOPIC, "EventTopic is null");
            final EventTopic eventTopic = EventTopic.valueOf(topicValue);
            handleIncomingEvent(message, eventTopic);
            break;
        default:
            logAndThrowMessageError(message, "No handle method was found for the given message type.");
        }
    } catch (final IllegalArgumentException ex) {
        throw new AmqpRejectAndDontRequeueException("Invalid message!", ex);
    } finally {
        SecurityContextHolder.setContext(oldContext);
    }
    return null;
}

From source file:org.flockdata.search.dao.EntityChangeWriterEs.java

/**
 * @param searchChange object containing changes
 * @param source       Json to save//  w ww  . java2  s .c  o m
 * @return key value of the child document
 */
private EntitySearchChange save(EntitySearchChange searchChange, String source) throws IOException {
    String indexName = searchChange.getIndexName();
    String documentType = searchChange.getDocumentType();
    logger.debug("Received request to Save [{}] SearchKey [{}]", searchChange.getKey(),
            searchChange.getSearchKey());

    // Rebuilding a document after a reindex - preserving the unique key.
    IndexRequestBuilder irb = elasticSearchClient.prepareIndex(searchChange.getIndexName(), documentType)
            .setSource(source);

    irb.setId(searchChange.getSearchKey());
    if (searchChange.getParent() != null)
        // Disabling parent document functionality
        //            irb.setParent(searchChange.getParent().getCode());
        irb.setRouting(searchChange.getParent().getCode());
    else
        irb.setRouting(searchChange.getCode());

    try {
        IndexResponse ir = irb.execute().actionGet();

        logger.debug("Save:Document entityId [{}], [{}], logId= [{}] searchKey [{}] index [{}/{}]",
                searchChange.getId(), searchChange.getKey(), searchChange.getLogId(), ir.getId(), indexName,
                documentType);

        return searchChange;
    } catch (MapperParsingException e) {
        // DAT-359
        logger.error("Parsing error {} - code [{}], key [{}], [{}]", indexName, searchChange.getCode(),
                searchChange.getKey(), e.getMessage());
        throw new AmqpRejectAndDontRequeueException("Parsing error - callerRef [" + searchChange.getCode()
                + "], key [" + searchChange.getKey() + "], " + e.getMessage(), e);
    } catch (Exception e) {
        logger.error("Writing to index {} produced an error [{}]", indexName, e.getMessage());
        throw new AmqpRejectAndDontRequeueException("Parsing error - callerRef [" + searchChange.getCode()
                + "], key [" + searchChange.getKey() + "], " + e.getMessage(), e);
    }

}

From source file:org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.java

/**
 * Execute the specified listener, committing or rolling back the transaction afterwards (if necessary).
 *
 * @param channel the Rabbit Channel to operate on
 * @param messageIn the received Rabbit Message
 * @throws Exception Any Exception./*from  w  w  w. jav a  2 s .com*/
 *
 * @see #invokeListener
 * @see #handleListenerException
 */
protected void executeListener(Channel channel, Message messageIn) throws Exception {
    if (!isRunning()) {
        if (logger.isWarnEnabled()) {
            logger.warn(
                    "Rejecting received message because the listener container has been stopped: " + messageIn);
        }
        throw new MessageRejectedWhileStoppingException();
    }
    try {
        Message message = messageIn;
        if (this.afterReceivePostProcessors != null) {
            for (MessagePostProcessor processor : this.afterReceivePostProcessors) {
                message = processor.postProcessMessage(message);
            }
        }
        Object batchFormat = message.getMessageProperties().getHeaders()
                .get(MessageProperties.SPRING_BATCH_FORMAT);
        if (MessageProperties.BATCH_FORMAT_LENGTH_HEADER4.equals(batchFormat) && this.deBatchingEnabled) {
            ByteBuffer byteBuffer = ByteBuffer.wrap(message.getBody());
            MessageProperties messageProperties = message.getMessageProperties();
            messageProperties.getHeaders().remove(MessageProperties.SPRING_BATCH_FORMAT);
            while (byteBuffer.hasRemaining()) {
                int length = byteBuffer.getInt();
                if (length < 0 || length > byteBuffer.remaining()) {
                    throw new ListenerExecutionFailedException("Bad batched message received",
                            new MessageConversionException(
                                    "Insufficient batch data at offset " + byteBuffer.position()),
                            message);
                }
                byte[] body = new byte[length];
                byteBuffer.get(body);
                messageProperties.setContentLength(length);
                // Caveat - shared MessageProperties.
                Message fragment = new Message(body, messageProperties);
                invokeListener(channel, fragment);
            }
        } else {
            invokeListener(channel, message);
        }
    } catch (Exception ex) {
        if (messageIn.getMessageProperties().isFinalRetryForMessageWithNoId()) {
            if (this.statefulRetryFatalWithNullMessageId) {
                throw new FatalListenerExecutionException(
                        "Illegal null id in message. Failed to manage retry for message: " + messageIn);
            } else {
                throw new ListenerExecutionFailedException("Cannot retry message more than once without an ID",
                        new AmqpRejectAndDontRequeueException("Not retryable; rejecting and not requeuing", ex),
                        messageIn);
            }
        }
        handleListenerException(ex);
        throw ex;
    }
}

From source file:org.springframework.amqp.rabbit.listener.ConditionalRejectingErrorHandler.java

@Override
public void handleError(Throwable t) {
    if (this.logger.isWarnEnabled()) {
        this.logger.warn("Execution of Rabbit message listener failed.", t);
    }/* w w  w  .j  ava 2s. c o m*/
    if (!this.causeChainContainsARADRE(t) && this.exceptionStrategy.isFatal(t)) {
        throw new AmqpRejectAndDontRequeueException("Error Handler converted exception to fatal", t);
    }
}