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);
});
}
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);
});
}
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);
});
}
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);
});
}
Aggregations