Search in sources :

Example 1 with MessageMimeTypeMetadata

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);
}
Also used : RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) MessageMimeTypeMetadata(com.alibaba.rsocket.metadata.MessageMimeTypeMetadata)

Example 2 with MessageMimeTypeMetadata

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);
}
Also used : RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) MessageMimeTypeMetadata(com.alibaba.rsocket.metadata.MessageMimeTypeMetadata)

Example 3 with MessageMimeTypeMetadata

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);
}
Also used : RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) MessageMimeTypeMetadata(com.alibaba.rsocket.metadata.MessageMimeTypeMetadata)

Example 4 with MessageMimeTypeMetadata

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!");
    }
}
Also used : RSocketBrokerResponderHandler(com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler) RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) TextArea(com.vaadin.flow.component.textfield.TextArea) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) Autowired(org.springframework.beans.factory.annotation.Autowired) RSocketBrokerHandlerRegistry(com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerHandlerRegistry) Route(com.vaadin.flow.router.Route) Unpooled(io.netty.buffer.Unpooled) MessageMimeTypeMetadata(com.alibaba.rsocket.metadata.MessageMimeTypeMetadata) ByteBuf(io.netty.buffer.ByteBuf) RSocketBrokerResponderHandler(com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler) TextField(com.vaadin.flow.component.textfield.TextField) ByteBufPayload(io.rsocket.util.ByteBufPayload) RSocketMimeType(com.alibaba.rsocket.metadata.RSocketMimeType) VerticalLayout(com.vaadin.flow.component.orderedlayout.VerticalLayout) H3(com.vaadin.flow.component.html.H3) ServiceRoutingSelector(com.alibaba.spring.boot.rsocket.broker.route.ServiceRoutingSelector) H4(com.vaadin.flow.component.html.H4) RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) StandardCharsets(java.nio.charset.StandardCharsets) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) Nullable(org.jetbrains.annotations.Nullable) Button(com.vaadin.flow.component.button.Button) Payload(io.rsocket.Payload) NAV(com.alibaba.rsocket.broker.web.ui.ServiceTestingView.NAV) Pre(com.vaadin.flow.component.html.Pre) ServiceLocator(com.alibaba.rsocket.ServiceLocator) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) MessageMimeTypeMetadata(com.alibaba.rsocket.metadata.MessageMimeTypeMetadata) ByteBufPayload(io.rsocket.util.ByteBufPayload) Payload(io.rsocket.Payload) ByteBuf(io.netty.buffer.ByteBuf)

Example 5 with MessageMimeTypeMetadata

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());
}
Also used : RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) MessageMimeTypeMetadata(com.alibaba.rsocket.metadata.MessageMimeTypeMetadata)

Aggregations

GSVRoutingMetadata (com.alibaba.rsocket.metadata.GSVRoutingMetadata)5 MessageMimeTypeMetadata (com.alibaba.rsocket.metadata.MessageMimeTypeMetadata)5 RSocketCompositeMetadata (com.alibaba.rsocket.metadata.RSocketCompositeMetadata)5 ServiceLocator (com.alibaba.rsocket.ServiceLocator)1 NAV (com.alibaba.rsocket.broker.web.ui.ServiceTestingView.NAV)1 RSocketMimeType (com.alibaba.rsocket.metadata.RSocketMimeType)1 RSocketBrokerHandlerRegistry (com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerHandlerRegistry)1 RSocketBrokerResponderHandler (com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler)1 ServiceRoutingSelector (com.alibaba.spring.boot.rsocket.broker.route.ServiceRoutingSelector)1 Button (com.vaadin.flow.component.button.Button)1 H3 (com.vaadin.flow.component.html.H3)1 H4 (com.vaadin.flow.component.html.H4)1 Pre (com.vaadin.flow.component.html.Pre)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 VerticalLayout (com.vaadin.flow.component.orderedlayout.VerticalLayout)1 TextArea (com.vaadin.flow.component.textfield.TextArea)1 TextField (com.vaadin.flow.component.textfield.TextField)1 Route (com.vaadin.flow.router.Route)1 ByteBuf (io.netty.buffer.ByteBuf)1 Unpooled (io.netty.buffer.Unpooled)1