Search in sources :

Example 1 with JsonRpcRequest

use of com.alibaba.spring.boot.rsocket.broker.cluster.jsonrpc.JsonRpcRequest in project alibaba-rsocket-broker by alibaba.

the class RSocketBrokerManagerGossipImpl method onMessage.

@Override
public void onMessage(Message message) {
    if (message.header("jsonrpc") != null) {
        JsonRpcRequest request = message.data();
        Message replyMessage = Message.builder().correlationId(message.correlationId()).data(onJsonRpcCall(request)).build();
        this.monoCluster.flatMap(cluster -> cluster.send(message.sender(), replyMessage)).subscribe();
    }
}
Also used : Sinks(reactor.core.publisher.Sinks) java.util(java.util) Json(com.alibaba.rsocket.cloudevents.Json) Cluster(io.scalecube.cluster.Cluster) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) JsonRpcResponse(com.alibaba.spring.boot.rsocket.broker.cluster.jsonrpc.JsonRpcResponse) Metrics(io.micrometer.core.instrument.Metrics) Value(org.springframework.beans.factory.annotation.Value) Shutdown(org.springframework.boot.web.server.Shutdown) CloudEventImpl(com.alibaba.rsocket.cloudevents.CloudEventImpl) RSocketFilterEnableEvent(com.alibaba.spring.boot.rsocket.broker.events.RSocketFilterEnableEvent) Message(io.scalecube.cluster.transport.api.Message) JsonRpcRequest(com.alibaba.spring.boot.rsocket.broker.cluster.jsonrpc.JsonRpcRequest) ClusterImpl(io.scalecube.cluster.ClusterImpl) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) DoubleFunction(org.eclipse.collections.api.block.function.primitive.DoubleFunction) Address(io.scalecube.net.Address) Logger(org.slf4j.Logger) RsocketErrorCode(com.alibaba.rsocket.observability.RsocketErrorCode) Mono(reactor.core.publisher.Mono) GracefulShutdownResult(org.springframework.boot.web.server.GracefulShutdownResult) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) SmartLifecycle(org.springframework.context.SmartLifecycle) RSocketFilter(com.alibaba.rsocket.route.RSocketFilter) Nullable(org.jetbrains.annotations.Nullable) Flux(reactor.core.publisher.Flux) Stream(java.util.stream.Stream) RSocketBrokerProperties(com.alibaba.spring.boot.rsocket.broker.RSocketBrokerProperties) Member(io.scalecube.cluster.Member) MembershipEvent(io.scalecube.cluster.membership.MembershipEvent) NetworkUtil(com.alibaba.rsocket.transport.NetworkUtil) TcpTransportFactory(io.scalecube.transport.netty.tcp.TcpTransportFactory) ClusterMessageHandler(io.scalecube.cluster.ClusterMessageHandler) NotNull(org.jetbrains.annotations.NotNull) ServiceLocator(com.alibaba.rsocket.ServiceLocator) GracefulShutdownCallback(org.springframework.boot.web.server.GracefulShutdownCallback) JsonRpcRequest(com.alibaba.spring.boot.rsocket.broker.cluster.jsonrpc.JsonRpcRequest) Message(io.scalecube.cluster.transport.api.Message)

Example 2 with JsonRpcRequest

use of com.alibaba.spring.boot.rsocket.broker.cluster.jsonrpc.JsonRpcRequest in project alibaba-rsocket-broker by alibaba.

the class RSocketBrokerManagerGossipImpl method makeJsonRpcCall.

public Mono<JsonRpcResponse> makeJsonRpcCall(@NotNull Member member, @NotNull String methodName, @Nullable Object params) {
    String uuid = UUID.randomUUID().toString();
    Message jsonRpcMessage = Message.builder().correlationId(uuid).header("jsonrpc", "2.0").data(new JsonRpcRequest(methodName, params, uuid)).build();
    return monoCluster.flatMap(cluster -> cluster.requestResponse(member, jsonRpcMessage)).map(Message::data);
}
Also used : Sinks(reactor.core.publisher.Sinks) java.util(java.util) Json(com.alibaba.rsocket.cloudevents.Json) Cluster(io.scalecube.cluster.Cluster) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) JsonRpcResponse(com.alibaba.spring.boot.rsocket.broker.cluster.jsonrpc.JsonRpcResponse) Metrics(io.micrometer.core.instrument.Metrics) Value(org.springframework.beans.factory.annotation.Value) Shutdown(org.springframework.boot.web.server.Shutdown) CloudEventImpl(com.alibaba.rsocket.cloudevents.CloudEventImpl) RSocketFilterEnableEvent(com.alibaba.spring.boot.rsocket.broker.events.RSocketFilterEnableEvent) Message(io.scalecube.cluster.transport.api.Message) JsonRpcRequest(com.alibaba.spring.boot.rsocket.broker.cluster.jsonrpc.JsonRpcRequest) ClusterImpl(io.scalecube.cluster.ClusterImpl) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) DoubleFunction(org.eclipse.collections.api.block.function.primitive.DoubleFunction) Address(io.scalecube.net.Address) Logger(org.slf4j.Logger) RsocketErrorCode(com.alibaba.rsocket.observability.RsocketErrorCode) Mono(reactor.core.publisher.Mono) GracefulShutdownResult(org.springframework.boot.web.server.GracefulShutdownResult) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) SmartLifecycle(org.springframework.context.SmartLifecycle) RSocketFilter(com.alibaba.rsocket.route.RSocketFilter) Nullable(org.jetbrains.annotations.Nullable) Flux(reactor.core.publisher.Flux) Stream(java.util.stream.Stream) RSocketBrokerProperties(com.alibaba.spring.boot.rsocket.broker.RSocketBrokerProperties) Member(io.scalecube.cluster.Member) MembershipEvent(io.scalecube.cluster.membership.MembershipEvent) NetworkUtil(com.alibaba.rsocket.transport.NetworkUtil) TcpTransportFactory(io.scalecube.transport.netty.tcp.TcpTransportFactory) ClusterMessageHandler(io.scalecube.cluster.ClusterMessageHandler) NotNull(org.jetbrains.annotations.NotNull) ServiceLocator(com.alibaba.rsocket.ServiceLocator) GracefulShutdownCallback(org.springframework.boot.web.server.GracefulShutdownCallback) Message(io.scalecube.cluster.transport.api.Message) JsonRpcRequest(com.alibaba.spring.boot.rsocket.broker.cluster.jsonrpc.JsonRpcRequest)

Aggregations

ServiceLocator (com.alibaba.rsocket.ServiceLocator)2 CloudEventImpl (com.alibaba.rsocket.cloudevents.CloudEventImpl)2 Json (com.alibaba.rsocket.cloudevents.Json)2 RsocketErrorCode (com.alibaba.rsocket.observability.RsocketErrorCode)2 RSocketFilter (com.alibaba.rsocket.route.RSocketFilter)2 NetworkUtil (com.alibaba.rsocket.transport.NetworkUtil)2 RSocketBrokerProperties (com.alibaba.spring.boot.rsocket.broker.RSocketBrokerProperties)2 JsonRpcRequest (com.alibaba.spring.boot.rsocket.broker.cluster.jsonrpc.JsonRpcRequest)2 JsonRpcResponse (com.alibaba.spring.boot.rsocket.broker.cluster.jsonrpc.JsonRpcResponse)2 RSocketFilterEnableEvent (com.alibaba.spring.boot.rsocket.broker.events.RSocketFilterEnableEvent)2 Metrics (io.micrometer.core.instrument.Metrics)2 Cluster (io.scalecube.cluster.Cluster)2 ClusterImpl (io.scalecube.cluster.ClusterImpl)2 ClusterMessageHandler (io.scalecube.cluster.ClusterMessageHandler)2 Member (io.scalecube.cluster.Member)2 MembershipEvent (io.scalecube.cluster.membership.MembershipEvent)2 Message (io.scalecube.cluster.transport.api.Message)2 Address (io.scalecube.net.Address)2 TcpTransportFactory (io.scalecube.transport.netty.tcp.TcpTransportFactory)2 java.util (java.util)2