Search in sources :

Example 1 with FrameType

use of io.rsocket.frame.FrameType in project spring-framework by spring-projects.

the class MessagingRSocket method handleAndReply.

@SuppressWarnings("deprecation")
private Flux<Payload> handleAndReply(Payload firstPayload, FrameType frameType, Flux<Payload> payloads) {
    AtomicReference<Flux<Payload>> responseRef = new AtomicReference<>();
    MessageHeaders headers = createHeaders(firstPayload, frameType, responseRef);
    AtomicBoolean read = new AtomicBoolean();
    Flux<DataBuffer> buffers = payloads.map(this::retainDataAndReleasePayload).doOnSubscribe(s -> read.set(true));
    Message<Flux<DataBuffer>> message = MessageBuilder.createMessage(buffers, headers);
    return Mono.defer(() -> this.messageHandler.handleMessage(message)).doFinally(s -> {
        // Subscription should have happened by now due to ChannelSendOperator
        if (!read.get()) {
            firstPayload.release();
        }
    }).thenMany(Flux.defer(() -> responseRef.get() != null ? responseRef.get() : Mono.error(new IllegalStateException("Expected response"))));
}
Also used : PayloadUtils(org.springframework.messaging.rsocket.PayloadUtils) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DestinationPatternsMessageCondition(org.springframework.messaging.handler.DestinationPatternsMessageCondition) AtomicReference(java.util.concurrent.atomic.AtomicReference) MetadataExtractor(org.springframework.messaging.rsocket.MetadataExtractor) RouteMatcher(org.springframework.util.RouteMatcher) HandlerMethodReturnValueHandler(org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler) MimeType(org.springframework.util.MimeType) RSocket(io.rsocket.RSocket) Map(java.util.Map) DataBufferUtils(org.springframework.core.io.buffer.DataBufferUtils) Nullable(org.springframework.lang.Nullable) Message(org.springframework.messaging.Message) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) NettyDataBuffer(org.springframework.core.io.buffer.NettyDataBuffer) MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) RSocketRequester(org.springframework.messaging.rsocket.RSocketRequester) FrameType(io.rsocket.frame.FrameType) Publisher(org.reactivestreams.Publisher) Mono(reactor.core.publisher.Mono) DataBuffer(org.springframework.core.io.buffer.DataBuffer) MessageHeaders(org.springframework.messaging.MessageHeaders) Flux(reactor.core.publisher.Flux) Payload(io.rsocket.Payload) ReactiveMessageHandler(org.springframework.messaging.ReactiveMessageHandler) ConnectionSetupPayload(io.rsocket.ConnectionSetupPayload) MessageBuilder(org.springframework.messaging.support.MessageBuilder) Assert(org.springframework.util.Assert) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Flux(reactor.core.publisher.Flux) AtomicReference(java.util.concurrent.atomic.AtomicReference) MessageHeaders(org.springframework.messaging.MessageHeaders) NettyDataBuffer(org.springframework.core.io.buffer.NettyDataBuffer) DataBuffer(org.springframework.core.io.buffer.DataBuffer)

Example 2 with FrameType

use of io.rsocket.frame.FrameType 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)

Aggregations

ConnectionSetupPayload (io.rsocket.ConnectionSetupPayload)2 RSocket (io.rsocket.RSocket)2 FrameType (io.rsocket.frame.FrameType)2 Nullable (org.springframework.lang.Nullable)2 Message (org.springframework.messaging.Message)2 DestinationPatternsMessageCondition (org.springframework.messaging.handler.DestinationPatternsMessageCondition)2 HandlerMethodReturnValueHandler (org.springframework.messaging.handler.invocation.reactive.HandlerMethodReturnValueHandler)2 MetadataExtractor (org.springframework.messaging.rsocket.MetadataExtractor)2 RSocketRequester (org.springframework.messaging.rsocket.RSocketRequester)2 RSocketStrategies (org.springframework.messaging.rsocket.RSocketStrategies)2 Assert (org.springframework.util.Assert)2 MimeType (org.springframework.util.MimeType)2 RouteMatcher (org.springframework.util.RouteMatcher)2 Mono (reactor.core.publisher.Mono)2 Payload (io.rsocket.Payload)1 SocketAcceptor (io.rsocket.SocketAcceptor)1 WellKnownMimeType (io.rsocket.metadata.WellKnownMimeType)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1