use of org.springframework.messaging.MessageDeliveryException in project spring-framework by spring-projects.
the class RSocketMessageHandler method handleNoMatch.
@Override
protected void handleNoMatch(@Nullable RouteMatcher.Route destination, Message<?> message) {
FrameType frameType = RSocketFrameTypeMessageCondition.getFrameType(message);
if (frameType == FrameType.SETUP || frameType == FrameType.METADATA_PUSH) {
// optional handling
return;
}
if (frameType == FrameType.REQUEST_FNF) {
// Can't propagate error to client, so just log
logger.warn("No handler for fireAndForget to '" + destination + "'");
return;
}
Set<FrameType> frameTypes = getHandlerMethods().keySet().stream().map(CompositeMessageCondition::getMessageConditions).filter(conditions -> conditions.get(1).getMatchingCondition(message) != null).map(conditions -> (RSocketFrameTypeMessageCondition) conditions.get(0)).flatMap(condition -> condition.getFrameTypes().stream()).collect(Collectors.toSet());
throw new MessageDeliveryException(frameTypes.isEmpty() ? "No handler for destination '" + destination + "'" : "Destination '" + destination + "' does not support " + frameType + ". " + "Supported interaction(s): " + frameTypes);
}
use of org.springframework.messaging.MessageDeliveryException in project spring-framework by spring-projects.
the class GenericMessagingTemplate method doSend.
protected final void doSend(MessageChannel channel, Message<?> message, long timeout) {
Assert.notNull(channel, "MessageChannel is required");
Message<?> messageToSend = message;
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
if (accessor != null && accessor.isMutable()) {
accessor.removeHeader(this.sendTimeoutHeader);
accessor.removeHeader(this.receiveTimeoutHeader);
accessor.setImmutable();
} else if (message.getHeaders().containsKey(this.sendTimeoutHeader) || message.getHeaders().containsKey(this.receiveTimeoutHeader)) {
messageToSend = MessageBuilder.fromMessage(message).setHeader(this.sendTimeoutHeader, null).setHeader(this.receiveTimeoutHeader, null).build();
}
boolean sent = (timeout >= 0 ? channel.send(messageToSend, timeout) : channel.send(messageToSend));
if (!sent) {
throw new MessageDeliveryException(message, "Failed to send message to channel '" + channel + "' within timeout: " + timeout);
}
}
Aggregations