Search in sources :

Example 6 with RSocketExchange

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));
        }
    });
}
Also used : RSocketExchange(com.alibaba.rsocket.RSocketExchange) InvalidException(io.rsocket.exceptions.InvalidException) CloudEventRSocket(com.alibaba.rsocket.cloudevents.CloudEventRSocket) RSocket(io.rsocket.RSocket) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

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