use of org.kin.rsocket.core.metadata.BinaryRoutingMetadata in project kin-rsocket-broker by huangjianqin.
the class BrokerRequestHandler method fireAndForget.
@Nonnull
@Override
public Mono<Void> fireAndForget(Payload payload) {
BinaryRoutingMetadata binaryRoutingMetadata = BinaryRoutingMetadata.extract(payload.metadata());
GSVRoutingMetadata gsvRoutingMetadata;
if (binaryRoutingMetadata != null) {
gsvRoutingMetadata = binaryRoutingMetadata.toGSVRoutingMetadata();
} else {
RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.of(payload.metadata());
gsvRoutingMetadata = compositeMetadata.getMetadata(RSocketMimeType.ROUTING);
if (gsvRoutingMetadata == null) {
return Mono.error(new InvalidException("No Routing metadata"));
}
}
// request filters
Mono<RSocket> destination;
if (this.filterChain.isFiltersPresent()) {
RSocketFilterContext filterContext = RSocketFilterContext.of(FrameType.REQUEST_FNF, gsvRoutingMetadata, this.upstreamBrokerMetadata, payload);
// filter可能会改变gsv metadata的数据, 影响路由结果
destination = filterChain.filter(filterContext).then(findDestination(gsvRoutingMetadata));
} else {
destination = findDestination(gsvRoutingMetadata);
}
// call destination
return destination.flatMap(rsocket -> {
MetricsUtils.metrics(gsvRoutingMetadata, FrameType.REQUEST_FNF.name());
return rsocket.fireAndForget(payload);
});
}
use of org.kin.rsocket.core.metadata.BinaryRoutingMetadata in project kin-rsocket-broker by huangjianqin.
the class BrokerRequestHandler method requestStream.
@Nonnull
@Override
public Flux<Payload> requestStream(Payload payload) {
BinaryRoutingMetadata binaryRoutingMetadata = BinaryRoutingMetadata.extract(payload.metadata());
GSVRoutingMetadata gsvRoutingMetadata;
if (binaryRoutingMetadata != null) {
gsvRoutingMetadata = binaryRoutingMetadata.toGSVRoutingMetadata();
} else {
RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.of(payload.metadata());
gsvRoutingMetadata = compositeMetadata.getMetadata(RSocketMimeType.ROUTING);
if (gsvRoutingMetadata == null) {
return Flux.error(new InvalidException("No Routing metadata"));
}
}
// request filters
Mono<RSocket> destination;
if (this.filterChain.isFiltersPresent()) {
RSocketFilterContext filterContext = RSocketFilterContext.of(FrameType.REQUEST_STREAM, gsvRoutingMetadata, this.upstreamBrokerMetadata, payload);
// filter可能会改变gsv metadata的数据, 影响路由结果
destination = filterChain.filter(filterContext).then(findDestination(gsvRoutingMetadata));
} else {
destination = findDestination(gsvRoutingMetadata);
}
return destination.flatMapMany(rsocket -> {
MetricsUtils.metrics(gsvRoutingMetadata, FrameType.REQUEST_STREAM.name());
return rsocket.requestStream(payload);
});
}
use of org.kin.rsocket.core.metadata.BinaryRoutingMetadata in project kin-rsocket-broker by huangjianqin.
the class BrokerRequestHandler method requestResponse.
@Nonnull
@Override
public Mono<Payload> requestResponse(Payload payload) {
BinaryRoutingMetadata binaryRoutingMetadata = BinaryRoutingMetadata.extract(payload.metadata());
GSVRoutingMetadata gsvRoutingMetadata;
if (binaryRoutingMetadata != null) {
gsvRoutingMetadata = binaryRoutingMetadata.toGSVRoutingMetadata();
} else {
RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.of(payload.metadata());
gsvRoutingMetadata = compositeMetadata.getMetadata(RSocketMimeType.ROUTING);
if (gsvRoutingMetadata == null) {
return Mono.error(new InvalidException("No Routing metadata"));
}
}
// request filters
Mono<RSocket> destination;
if (this.filterChain.isFiltersPresent()) {
RSocketFilterContext filterContext = RSocketFilterContext.of(FrameType.REQUEST_RESPONSE, gsvRoutingMetadata, this.upstreamBrokerMetadata, payload);
// filter可能会改变gsv metadata的数据, 影响路由结果
destination = filterChain.filter(filterContext).then(findDestination(gsvRoutingMetadata));
} else {
destination = findDestination(gsvRoutingMetadata);
}
// call destination
return destination.flatMap(rsocket -> {
MetricsUtils.metrics(gsvRoutingMetadata, FrameType.REQUEST_RESPONSE.name());
return rsocket.requestResponse(payload);
});
}
use of org.kin.rsocket.core.metadata.BinaryRoutingMetadata in project kin-rsocket-broker by huangjianqin.
the class BrokerRequestHandler method requestChannel.
private Flux<Payload> requestChannel(Payload signal, Publisher<Payload> payloads) {
BinaryRoutingMetadata binaryRoutingMetadata = BinaryRoutingMetadata.extract(signal.metadata());
GSVRoutingMetadata gsvRoutingMetadata;
if (binaryRoutingMetadata != null) {
gsvRoutingMetadata = binaryRoutingMetadata.toGSVRoutingMetadata();
} else {
RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.of(signal.metadata());
gsvRoutingMetadata = compositeMetadata.getMetadata(RSocketMimeType.ROUTING);
if (gsvRoutingMetadata == null) {
return Flux.error(new InvalidException("No Routing metadata"));
}
}
Mono<RSocket> destination = findDestination(gsvRoutingMetadata);
return destination.flatMapMany(rsocket -> {
MetricsUtils.metrics(gsvRoutingMetadata, FrameType.REQUEST_CHANNEL.name());
return rsocket.requestChannel(payloads);
});
}
Aggregations