use of com.alibaba.rsocket.RSocketExchange in project alibaba-rsocket-broker by alibaba.
the class RSocketBrokerResponderHandler method requestResponse.
@Override
@NotNull
public Mono<Payload> requestResponse(Payload payload) {
BinaryRoutingMetadata binaryRoutingMetadata = binaryRoutingMetadata(payload.metadata());
GSVRoutingMetadata gsvRoutingMetadata;
Integer serviceId;
final boolean encodingMetadataIncluded;
if (binaryRoutingMetadata != null) {
gsvRoutingMetadata = GSVRoutingMetadata.from(new String(binaryRoutingMetadata.getRoutingText(), StandardCharsets.UTF_8));
serviceId = binaryRoutingMetadata.getServiceId();
encodingMetadataIncluded = true;
} else {
RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(payload.metadata());
gsvRoutingMetadata = compositeMetadata.getRoutingMetaData();
if (gsvRoutingMetadata == null) {
return Mono.error(new InvalidException(RsocketErrorCode.message("RST-600404")));
}
encodingMetadataIncluded = compositeMetadata.contains(RSocketMimeType.MessageMimeType);
serviceId = gsvRoutingMetadata.id();
}
// broker local service call check: don't introduce interceptor, performance consideration
if (localServiceCaller.contains(serviceId)) {
return localRequestResponse(gsvRoutingMetadata, defaultMessageMimeType, null, payload);
}
// request filters
Mono<RSocket> destination = findDestination(binaryRoutingMetadata, gsvRoutingMetadata);
if (this.filterChain.isFiltersPresent()) {
RSocketExchange exchange = new RSocketExchange(FrameType.REQUEST_RESPONSE, gsvRoutingMetadata, payload, this.appMetadata);
destination = filterChain.filter(exchange).then(destination);
}
// call destination
return destination.flatMap(rsocket -> {
recordServiceInvoke(principal.getName(), gsvRoutingMetadata.gsv());
metrics(gsvRoutingMetadata, "0x05");
if (encodingMetadataIncluded) {
return rsocket.requestResponse(payload);
} else {
return rsocket.requestResponse(payloadWithDataEncoding(payload));
}
});
}
use of com.alibaba.rsocket.RSocketExchange in project alibaba-rsocket-broker by alibaba.
the class RSocketBrokerResponderHandler method requestStream.
@Override
@NotNull
public Flux<Payload> requestStream(Payload payload) {
BinaryRoutingMetadata binaryRoutingMetadata = binaryRoutingMetadata(payload.metadata());
GSVRoutingMetadata gsvRoutingMetadata;
Integer serviceId;
final boolean encodingMetadataIncluded;
if (binaryRoutingMetadata != null) {
gsvRoutingMetadata = GSVRoutingMetadata.from(new String(binaryRoutingMetadata.getRoutingText(), StandardCharsets.UTF_8));
serviceId = binaryRoutingMetadata.getServiceId();
encodingMetadataIncluded = true;
} else {
RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(payload.metadata());
gsvRoutingMetadata = compositeMetadata.getRoutingMetaData();
if (gsvRoutingMetadata == null) {
return Flux.error(new InvalidException(RsocketErrorCode.message("RST-600404")));
}
encodingMetadataIncluded = compositeMetadata.contains(RSocketMimeType.MessageMimeType);
serviceId = gsvRoutingMetadata.id();
}
// broker local service call check: don't introduce interceptor, performance consideration
if (localServiceCaller.contains(serviceId)) {
return localRequestStream(gsvRoutingMetadata, defaultMessageMimeType, null, payload);
}
Mono<RSocket> destination = findDestination(binaryRoutingMetadata, gsvRoutingMetadata);
if (this.filterChain.isFiltersPresent()) {
RSocketExchange requestContext = new RSocketExchange(FrameType.REQUEST_STREAM, gsvRoutingMetadata, payload, this.appMetadata);
destination = filterChain.filter(requestContext).then(destination);
}
return destination.flatMapMany(rsocket -> {
recordServiceInvoke(principal.getName(), gsvRoutingMetadata.gsv());
metrics(gsvRoutingMetadata, "0x06");
if (encodingMetadataIncluded) {
return rsocket.requestStream(payload);
} else {
return rsocket.requestStream(payloadWithDataEncoding(payload));
}
});
}
use of com.alibaba.rsocket.RSocketExchange 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.RSocketExchange 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.RSocketExchange 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