Search in sources :

Example 1 with AcknowledgmentCallback

use of org.springframework.integration.support.AcknowledgmentCallback in project spring-cloud-stream by spring-cloud.

the class DefaultPollableMessageSource method poll.

@Override
public boolean poll(MessageHandler handler, ParameterizedTypeReference<?> type) {
    Message<?> message = this.receive(type);
    if (message == null) {
        return false;
    }
    AcknowledgmentCallback ackCallback = StaticMessageHeaderAccessor.getAcknowledgmentCallback(message);
    try {
        if (this.retryTemplate == null) {
            if (this.errorChannel == null) {
                this.handle(message, handler);
            } else {
                try {
                    this.handle(message, handler);
                } catch (Exception e) {
                    this.messagingTemplate.send(this.errorChannel, this.errorMessageStrategy.buildErrorMessage(e, attributesHolder.get()));
                }
            }
        } else {
            this.retryTemplate.execute(context -> {
                this.handle(message, handler);
                return null;
            }, this.recoveryCallback);
        }
        return true;
    } catch (Exception e) {
        AckUtils.autoNack(ackCallback);
        if (e instanceof MessageHandlingException && ((MessageHandlingException) e).getFailedMessage().equals(message)) {
            throw (MessageHandlingException) e;
        }
        throw new MessageHandlingException(message, e);
    } finally {
        AckUtils.autoAck(ackCallback);
    }
}
Also used : AcknowledgmentCallback(org.springframework.integration.support.AcknowledgmentCallback) MessageHandlingException(org.springframework.messaging.MessageHandlingException) MessageConversionException(org.springframework.messaging.converter.MessageConversionException) MessageHandlingException(org.springframework.messaging.MessageHandlingException)

Aggregations

AcknowledgmentCallback (org.springframework.integration.support.AcknowledgmentCallback)1 MessageHandlingException (org.springframework.messaging.MessageHandlingException)1 MessageConversionException (org.springframework.messaging.converter.MessageConversionException)1