use of com.alibaba.rsocket.RSocketExchange in project alibaba-rsocket-broker by alibaba.
the class RSocketBrokerResponderHandler method fireAndForget.
@Override
@NotNull
public Mono<Void> fireAndForget(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();
}
if (localServiceCaller.contains(serviceId)) {
return localFireAndForget(gsvRoutingMetadata, defaultMessageMimeType, payload);
}
// request filters
Mono<RSocket> destination = findDestination(binaryRoutingMetadata, gsvRoutingMetadata);
if (this.filterChain.isFiltersPresent()) {
RSocketExchange exchange = new RSocketExchange(FrameType.REQUEST_FNF, 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.fireAndForget(payload);
} else {
return rsocket.fireAndForget(payloadWithDataEncoding(payload));
}
});
}
Aggregations