Search in sources :

Example 1 with BinaryRoutingMetadata

use of com.alibaba.rsocket.metadata.BinaryRoutingMetadata 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 2 with BinaryRoutingMetadata

use of com.alibaba.rsocket.metadata.BinaryRoutingMetadata 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 3 with BinaryRoutingMetadata

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

the class UpstreamForwardRSocket method requestResponse.

@Override
@NotNull
public Mono<Payload> requestResponse(@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 Mono.error(new InvalidException(RsocketErrorCode.message("RST-600404")));
        }
    }
    // request filters
    Mono<RSocket> destination = findDestination(gsvRoutingMetadata);
    if (this.filterChain.isFiltersPresent()) {
        RSocketExchange exchange = new RSocketExchange(FrameType.REQUEST_RESPONSE, gsvRoutingMetadata, payload, this.upstreamBrokerMetadata);
        destination = filterChain.filter(exchange).then(destination);
    }
    // call destination
    return destination.flatMap(rsocket -> {
        metrics(gsvRoutingMetadata, "0x05");
        return rsocket.requestResponse(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 BinaryRoutingMetadata

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

the class UpstreamForwardRSocket method fireAndForget.

@Override
@NotNull
public Mono<Void> fireAndForget(@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 Mono.error(new InvalidException(RsocketErrorCode.message("RST-600404")));
        }
    }
    // request filters
    Mono<RSocket> destination = findDestination(gsvRoutingMetadata);
    if (this.filterChain.isFiltersPresent()) {
        RSocketExchange exchange = new RSocketExchange(FrameType.REQUEST_FNF, gsvRoutingMetadata, payload, this.upstreamBrokerMetadata);
        destination = filterChain.filter(exchange).then(destination);
    }
    // call destination
    return destination.flatMap(rsocket -> {
        metrics(gsvRoutingMetadata, "0x05");
        return rsocket.fireAndForget(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)

Aggregations

AbstractRSocket (com.alibaba.rsocket.AbstractRSocket)4 BinaryRoutingMetadata (com.alibaba.rsocket.metadata.BinaryRoutingMetadata)4 GSVRoutingMetadata (com.alibaba.rsocket.metadata.GSVRoutingMetadata)4 RSocketCompositeMetadata (com.alibaba.rsocket.metadata.RSocketCompositeMetadata)4 RSocket (io.rsocket.RSocket)4 InvalidException (io.rsocket.exceptions.InvalidException)4 RSocketExchange (com.alibaba.rsocket.RSocketExchange)3 NotNull (org.jetbrains.annotations.NotNull)3