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