Search in sources :

Example 46 with MessageDeliveryException

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);
}
Also used : AnnotatedElementUtils(org.springframework.core.annotation.AnnotatedElementUtils) Decoder(org.springframework.core.codec.Decoder) DestinationPatternsMessageCondition(org.springframework.messaging.handler.DestinationPatternsMessageCondition) MetadataExtractor(org.springframework.messaging.rsocket.MetadataExtractor) RouteMatcher(org.springframework.util.RouteMatcher) HandlerMethodReturnValueHandler(org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler) ConnectMapping(org.springframework.messaging.rsocket.annotation.ConnectMapping) ArrayList(java.util.ArrayList) MimeType(org.springframework.util.MimeType) WellKnownMimeType(io.rsocket.metadata.WellKnownMimeType) RSocket(io.rsocket.RSocket) MethodParameter(org.springframework.core.MethodParameter) Nullable(org.springframework.lang.Nullable) Message(org.springframework.messaging.Message) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) Encoder(org.springframework.core.codec.Encoder) ReactiveAdapterRegistry(org.springframework.core.ReactiveAdapterRegistry) RSocketRequester(org.springframework.messaging.rsocket.RSocketRequester) FrameType(io.rsocket.frame.FrameType) ReactiveAdapter(org.springframework.core.ReactiveAdapter) MessageCondition(org.springframework.messaging.handler.MessageCondition) Predicate(java.util.function.Predicate) Set(java.util.Set) Mono(reactor.core.publisher.Mono) MimeTypeUtils(org.springframework.util.MimeTypeUtils) SocketAcceptor(io.rsocket.SocketAcceptor) Collectors(java.util.stream.Collectors) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) List(java.util.List) CompositeMessageCondition(org.springframework.messaging.handler.CompositeMessageCondition) MessageMappingMessageHandler(org.springframework.messaging.handler.annotation.reactive.MessageMappingMessageHandler) HandlerMethod(org.springframework.messaging.handler.HandlerMethod) ConnectionSetupPayload(io.rsocket.ConnectionSetupPayload) PayloadMethodArgumentResolver(org.springframework.messaging.handler.annotation.reactive.PayloadMethodArgumentResolver) AnnotatedElement(java.lang.reflect.AnnotatedElement) BeanUtils(org.springframework.beans.BeanUtils) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) CompositeMessageCondition(org.springframework.messaging.handler.CompositeMessageCondition) FrameType(io.rsocket.frame.FrameType) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException)

Example 47 with MessageDeliveryException

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);
    }
}
Also used : MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException)

Aggregations

MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)47 Test (org.junit.Test)19 GenericMessage (org.springframework.messaging.support.GenericMessage)17 QueueChannel (org.springframework.integration.channel.QueueChannel)13 MessagingException (org.springframework.messaging.MessagingException)10 MessageChannel (org.springframework.messaging.MessageChannel)8 Message (org.springframework.messaging.Message)6 BeanFactory (org.springframework.beans.factory.BeanFactory)5 DirectChannel (org.springframework.integration.channel.DirectChannel)5 MessageHandler (org.springframework.messaging.MessageHandler)5 MessageHeaders (org.springframework.messaging.MessageHeaders)4 PollableChannel (org.springframework.messaging.PollableChannel)4 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 SubscribableChannel (org.springframework.messaging.SubscribableChannel)3 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)3 FileNotFoundException (java.io.FileNotFoundException)2 Date (java.util.Date)2 List (java.util.List)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2