use of com.alibaba.rsocket.metadata.MessageMimeTypeMetadata 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.MessageMimeTypeMetadata 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.MessageMimeTypeMetadata in project alibaba-broker-kotlin-example by alibaba-rsocket-broker.
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.MessageMimeTypeMetadata in project alibaba-rsocket-broker by alibaba.
the class ServiceTestingView method callRSocketService.
public void callRSocketService(String service, String method, @Nullable String jsonData, Pre response) {
Integer handlerId = this.routingSelector.findHandler(ServiceLocator.serviceHashCode(service));
if (handlerId != null) {
RSocketBrokerResponderHandler handler = handlerRegistry.findById(handlerId);
if (handler != null) {
// composite metadata for health check
RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(new GSVRoutingMetadata(null, service, method, null), new MessageMimeTypeMetadata(RSocketMimeType.Json));
ByteBuf payLoadData;
if (jsonData == null || jsonData.isEmpty()) {
payLoadData = Unpooled.EMPTY_BUFFER;
} else {
payLoadData = Unpooled.wrappedBuffer(jsonData.getBytes(StandardCharsets.UTF_8));
}
Payload requestPayload = ByteBufPayload.create(payLoadData, compositeMetadata.getContent());
handler.getPeerRsocket().requestResponse(requestPayload).doOnError(throwable -> getUI().ifPresent(ui -> ui.access(() -> {
response.setText(throwable.getMessage());
}))).subscribe(payload -> getUI().ifPresent(ui -> ui.access(() -> {
response.setText(payload.getDataUtf8());
})));
} else {
this.serviceNameFiled.setInvalid(true);
this.serviceNameFiled.setErrorMessage("No Service Provider!");
}
} else {
this.serviceNameFiled.setInvalid(true);
this.serviceNameFiled.setErrorMessage("Service not found!");
}
}
use of com.alibaba.rsocket.metadata.MessageMimeTypeMetadata in project alibaba-rsocket-broker by alibaba.
the class CloudEventRSocket method constructEventReplyPayload.
default Payload constructEventReplyPayload(URI replyTo, EventReply eventReply) {
String path = replyTo.getPath();
String serviceName = path.substring(path.lastIndexOf("/") + 1);
String method = replyTo.getFragment();
RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(new GSVRoutingMetadata("", serviceName, method, ""), new MessageMimeTypeMetadata(WellKnownMimeType.APPLICATION_JSON));
return ByteBufPayload.create(JsonUtils.toJsonByteBuf(eventReply), compositeMetadata.getContent());
}
Aggregations