use of com.alibaba.rsocket.metadata.GSVRoutingMetadata in project alibaba-broker-example-parent by linux-china.
the class UserServiceRSocketTest method testFindById.
@Test
public void testFindById() throws Exception {
RSocketCompositeMetadata compositeMetadata = new RSocketCompositeMetadata();
GSVRoutingMetadata routingMetadata = new GSVRoutingMetadata("", "com.alibaba.user.UserService2", "findById", "");
compositeMetadata.addMetadata(routingMetadata);
MessageMimeTypeMetadata dataEncodingMetadata = new MessageMimeTypeMetadata(WellKnownMimeType.APPLICATION_JSON);
compositeMetadata.addMetadata(dataEncodingMetadata);
rsocket.requestResponse(DefaultPayload.create(Unpooled.wrappedBuffer(objectMapper.writeValueAsBytes(1)), compositeMetadata.getContent())).doOnTerminate(() -> {
ReferenceCountUtil.safeRelease(compositeMetadata);
}).subscribe(payload -> {
System.out.println(payload.getDataUtf8());
});
Thread.sleep(1000);
}
use of com.alibaba.rsocket.metadata.GSVRoutingMetadata 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.GSVRoutingMetadata 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.GSVRoutingMetadata in project alibaba-rsocket-broker by alibaba.
the class UserServiceTest method testFindById.
@Test
public void testFindById() throws Exception {
RSocketCompositeMetadata compositeMetadata = new RSocketCompositeMetadata();
GSVRoutingMetadata routingMetadata = new GSVRoutingMetadata("", "com.alibaba.user.UserService2", "findById", "");
compositeMetadata.addMetadata(routingMetadata);
MessageMimeTypeMetadata dataEncodingMetadata = new MessageMimeTypeMetadata(WellKnownMimeType.APPLICATION_JSON);
compositeMetadata.addMetadata(dataEncodingMetadata);
rsocket.requestResponse(DefaultPayload.create(Unpooled.wrappedBuffer(objectMapper.writeValueAsBytes(1)), compositeMetadata.getContent())).doOnTerminate(() -> {
ReferenceCountUtil.safeRelease(compositeMetadata);
}).subscribe(payload -> {
System.out.println(payload.getDataUtf8());
});
Thread.sleep(1000);
}
use of com.alibaba.rsocket.metadata.GSVRoutingMetadata in project rsocket-graphql-gateway by alibaba-rsocket-broker.
the class MainController method executeRequest.
private Mono<ResponseEntity<ByteBuf>> executeRequest(String clusterName, GraphQLInvocationData invocationData, String authorizationValue) {
boolean authenticated;
if (!authRequired) {
authenticated = true;
} else {
authenticated = authAuthorizationValue(authorizationValue);
}
if (!authenticated) {
return Mono.error(new Exception(RsocketErrorCode.message("RST-500403")));
}
try {
GSVRoutingMetadata routingMetadata = new GSVRoutingMetadata(clusterName, GRAPHQL_SERVICE_NAME, "execute", "");
RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(routingMetadata, graphqlEncoding);
ByteBuf bodyBuf = Unpooled.wrappedBuffer(objectMapper.writeValueAsBytes(invocationData));
return rsocket.requestResponse(ByteBufPayload.create(bodyBuf, compositeMetadata.getContent())).map(payload -> {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.setCacheControl(CacheControl.noCache().getHeaderValue());
return new ResponseEntity<>(payload.data(), headers, HttpStatus.OK);
});
} catch (Exception e) {
return Mono.error(e);
}
}
Aggregations