Search in sources :

Example 1 with GSVRoutingMetadata

use of com.alibaba.rsocket.metadata.GSVRoutingMetadata in project alibaba-broker-example-parent by linux-china.

the class UserServiceRSocketTest method testFindById.

@Test
public void testFindById() throws Exception {
    RSocketCompositeMetadata compositeMetadata = new RSocketCompositeMetadata();
    GSVRoutingMetadata routingMetadata = new GSVRoutingMetadata("", "com.alibaba.user.UserService2", "findById", "");
    compositeMetadata.addMetadata(routingMetadata);
    MessageMimeTypeMetadata dataEncodingMetadata = new MessageMimeTypeMetadata(WellKnownMimeType.APPLICATION_JSON);
    compositeMetadata.addMetadata(dataEncodingMetadata);
    rsocket.requestResponse(DefaultPayload.create(Unpooled.wrappedBuffer(objectMapper.writeValueAsBytes(1)), compositeMetadata.getContent())).doOnTerminate(() -> {
        ReferenceCountUtil.safeRelease(compositeMetadata);
    }).subscribe(payload -> {
        System.out.println(payload.getDataUtf8());
    });
    Thread.sleep(1000);
}
Also used : RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) MessageMimeTypeMetadata(com.alibaba.rsocket.metadata.MessageMimeTypeMetadata)

Example 2 with GSVRoutingMetadata

use of com.alibaba.rsocket.metadata.GSVRoutingMetadata in project alibaba-rsocket-broker by alibaba.

the class UpstreamForwardRSocket method requestChannel.

public Flux<Payload> requestChannel(Payload signal, Publisher<Payload> payloads) {
    BinaryRoutingMetadata binaryRoutingMetadata = binaryRoutingMetadata(signal.metadata());
    GSVRoutingMetadata gsvRoutingMetadata;
    if (binaryRoutingMetadata != null) {
        gsvRoutingMetadata = GSVRoutingMetadata.from(new String(binaryRoutingMetadata.getRoutingText(), StandardCharsets.UTF_8));
    } else {
        RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(signal.metadata());
        gsvRoutingMetadata = compositeMetadata.getRoutingMetaData();
        if (gsvRoutingMetadata == null) {
            return Flux.error(new InvalidException(RsocketErrorCode.message("RST-600404")));
        }
    }
    Mono<RSocket> destination = findDestination(gsvRoutingMetadata);
    return destination.flatMapMany(rsocket -> {
        metrics(gsvRoutingMetadata, "0x07");
        return rsocket.requestChannel(payloads);
    });
}
Also used : RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) BinaryRoutingMetadata(com.alibaba.rsocket.metadata.BinaryRoutingMetadata) InvalidException(io.rsocket.exceptions.InvalidException) RSocket(io.rsocket.RSocket) AbstractRSocket(com.alibaba.rsocket.AbstractRSocket)

Example 3 with GSVRoutingMetadata

use of com.alibaba.rsocket.metadata.GSVRoutingMetadata in project alibaba-rsocket-broker by alibaba.

the class UpstreamForwardRSocket method requestStream.

@Override
@NotNull
public Flux<Payload> requestStream(@NotNull Payload payload) {
    BinaryRoutingMetadata binaryRoutingMetadata = binaryRoutingMetadata(payload.metadata());
    GSVRoutingMetadata gsvRoutingMetadata;
    if (binaryRoutingMetadata != null) {
        gsvRoutingMetadata = GSVRoutingMetadata.from(new String(binaryRoutingMetadata.getRoutingText(), StandardCharsets.UTF_8));
    } else {
        RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(payload.metadata());
        gsvRoutingMetadata = compositeMetadata.getRoutingMetaData();
        if (gsvRoutingMetadata == null) {
            return Flux.error(new InvalidException(RsocketErrorCode.message("RST-600404")));
        }
    }
    Mono<RSocket> destination = findDestination(gsvRoutingMetadata);
    if (this.filterChain.isFiltersPresent()) {
        RSocketExchange requestContext = new RSocketExchange(FrameType.REQUEST_STREAM, gsvRoutingMetadata, payload, this.upstreamBrokerMetadata);
        destination = filterChain.filter(requestContext).then(destination);
    }
    return destination.flatMapMany(rsocket -> {
        metrics(gsvRoutingMetadata, "0x06");
        return rsocket.requestStream(payload);
    });
}
Also used : RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) RSocketExchange(com.alibaba.rsocket.RSocketExchange) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) BinaryRoutingMetadata(com.alibaba.rsocket.metadata.BinaryRoutingMetadata) InvalidException(io.rsocket.exceptions.InvalidException) RSocket(io.rsocket.RSocket) AbstractRSocket(com.alibaba.rsocket.AbstractRSocket) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GSVRoutingMetadata

use of com.alibaba.rsocket.metadata.GSVRoutingMetadata in project alibaba-rsocket-broker by alibaba.

the class UserServiceTest method testFindById.

@Test
public void testFindById() throws Exception {
    RSocketCompositeMetadata compositeMetadata = new RSocketCompositeMetadata();
    GSVRoutingMetadata routingMetadata = new GSVRoutingMetadata("", "com.alibaba.user.UserService2", "findById", "");
    compositeMetadata.addMetadata(routingMetadata);
    MessageMimeTypeMetadata dataEncodingMetadata = new MessageMimeTypeMetadata(WellKnownMimeType.APPLICATION_JSON);
    compositeMetadata.addMetadata(dataEncodingMetadata);
    rsocket.requestResponse(DefaultPayload.create(Unpooled.wrappedBuffer(objectMapper.writeValueAsBytes(1)), compositeMetadata.getContent())).doOnTerminate(() -> {
        ReferenceCountUtil.safeRelease(compositeMetadata);
    }).subscribe(payload -> {
        System.out.println(payload.getDataUtf8());
    });
    Thread.sleep(1000);
}
Also used : RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) MessageMimeTypeMetadata(com.alibaba.rsocket.metadata.MessageMimeTypeMetadata)

Example 5 with GSVRoutingMetadata

use of com.alibaba.rsocket.metadata.GSVRoutingMetadata in project rsocket-graphql-gateway by alibaba-rsocket-broker.

the class MainController method executeRequest.

private Mono<ResponseEntity<ByteBuf>> executeRequest(String clusterName, GraphQLInvocationData invocationData, String authorizationValue) {
    boolean authenticated;
    if (!authRequired) {
        authenticated = true;
    } else {
        authenticated = authAuthorizationValue(authorizationValue);
    }
    if (!authenticated) {
        return Mono.error(new Exception(RsocketErrorCode.message("RST-500403")));
    }
    try {
        GSVRoutingMetadata routingMetadata = new GSVRoutingMetadata(clusterName, GRAPHQL_SERVICE_NAME, "execute", "");
        RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(routingMetadata, graphqlEncoding);
        ByteBuf bodyBuf = Unpooled.wrappedBuffer(objectMapper.writeValueAsBytes(invocationData));
        return rsocket.requestResponse(ByteBufPayload.create(bodyBuf, compositeMetadata.getContent())).map(payload -> {
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON);
            headers.setCacheControl(CacheControl.noCache().getHeaderValue());
            return new ResponseEntity<>(payload.data(), headers, HttpStatus.OK);
        });
    } catch (Exception e) {
        return Mono.error(e);
    }
}
Also used : RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

GSVRoutingMetadata (com.alibaba.rsocket.metadata.GSVRoutingMetadata)14 RSocketCompositeMetadata (com.alibaba.rsocket.metadata.RSocketCompositeMetadata)13 MessageMimeTypeMetadata (com.alibaba.rsocket.metadata.MessageMimeTypeMetadata)6 ByteBuf (io.netty.buffer.ByteBuf)5 AbstractRSocket (com.alibaba.rsocket.AbstractRSocket)4 BinaryRoutingMetadata (com.alibaba.rsocket.metadata.BinaryRoutingMetadata)4 RSocket (io.rsocket.RSocket)4 InvalidException (io.rsocket.exceptions.InvalidException)4 RSocketExchange (com.alibaba.rsocket.RSocketExchange)3 NotNull (org.jetbrains.annotations.NotNull)3 ServiceLocator (com.alibaba.rsocket.ServiceLocator)2 RSocketMimeType (com.alibaba.rsocket.metadata.RSocketMimeType)2 RSocketBrokerHandlerRegistry (com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerHandlerRegistry)2 RSocketBrokerResponderHandler (com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler)2 ServiceRoutingSelector (com.alibaba.spring.boot.rsocket.broker.route.ServiceRoutingSelector)2 Unpooled (io.netty.buffer.Unpooled)2 Payload (io.rsocket.Payload)2 ByteBufPayload (io.rsocket.util.ByteBufPayload)2 Nullable (org.jetbrains.annotations.Nullable)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2