Search in sources :

Example 1 with Message

use of io.scalecube.cluster.transport.api.Message in project kin-rsocket-broker by huangjianqin.

the class GossipBrokerManager method onMessage.

@Override
public void onMessage(Message message) {
    if (message.header(BROKER_INFO_HEADER) != null) {
        Message replyMessage = Message.builder().correlationId(message.correlationId()).data(localBrokerInfo).build();
        this.cluster.flatMap(cluster -> cluster.send(message.sender(), replyMessage)).subscribe();
    }
}
Also used : Sinks(reactor.core.publisher.Sinks) CloudEventBuilder(org.kin.rsocket.core.event.CloudEventBuilder) java.util(java.util) Cluster(io.scalecube.cluster.Cluster) LoggerFactory(org.slf4j.LoggerFactory) RSocketBrokerManager(org.kin.rsocket.broker.cluster.RSocketBrokerManager) Metrics(io.micrometer.core.instrument.Metrics) JacksonMessageCodec(io.scalecube.cluster.codec.jackson.JacksonMessageCodec) RSocketBrokerProperties(org.kin.rsocket.broker.RSocketBrokerProperties) Message(io.scalecube.cluster.transport.api.Message) ClusterImpl(io.scalecube.cluster.ClusterImpl) BrokerInfo(org.kin.rsocket.broker.cluster.BrokerInfo) JSON(org.kin.rsocket.core.utils.JSON) Address(io.scalecube.net.Address) Logger(org.slf4j.Logger) CloudEventData(org.kin.rsocket.core.event.CloudEventData) RSocketAppContext(org.kin.rsocket.core.RSocketAppContext) AbstractRSocketBrokerManager(org.kin.rsocket.broker.cluster.AbstractRSocketBrokerManager) Mono(reactor.core.publisher.Mono) MetricsNames(org.kin.rsocket.core.MetricsNames) Collectors(java.util.stream.Collectors) StringUtils(org.kin.framework.utils.StringUtils) Flux(reactor.core.publisher.Flux) Stream(java.util.stream.Stream) Member(io.scalecube.cluster.Member) DisposableBean(org.springframework.beans.factory.DisposableBean) MembershipEvent(io.scalecube.cluster.membership.MembershipEvent) PostConstruct(javax.annotation.PostConstruct) TcpTransportFactory(io.scalecube.transport.netty.tcp.TcpTransportFactory) ClusterMessageHandler(io.scalecube.cluster.ClusterMessageHandler) NetUtils(org.kin.framework.utils.NetUtils) Message(io.scalecube.cluster.transport.api.Message)

Example 2 with Message

use of io.scalecube.cluster.transport.api.Message 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 3 with Message

use of io.scalecube.cluster.transport.api.Message 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)

Example 4 with Message

use of io.scalecube.cluster.transport.api.Message in project alibaba-rsocket-broker by alibaba.

the class RSocketBrokerManagerGossipImplTest method testGossipMessageWithCloudEvents.

@Test
public void testGossipMessageWithCloudEvents() throws Exception {
    AppStatusEvent appStatusEvent = new AppStatusEvent("1", 1);
    CloudEventImpl<AppStatusEvent> cloudEvent = RSocketCloudEventBuilder.builder(appStatusEvent).withSubject("app status update").build();
    Message message = Message.builder().correlationId("1").data(cloudEvent).build();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    messageCodec.serialize(message, bos);
    Message message1 = messageCodec.deserialize(new ByteArrayInputStream(bos.toByteArray()));
    CloudEventImpl<AppStatusEvent> cloudEvent2 = message1.data();
    Assertions.assertThat(cloudEvent2.getData()).isPresent();
}
Also used : Message(io.scalecube.cluster.transport.api.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AppStatusEvent(com.alibaba.rsocket.events.AppStatusEvent) Test(org.junit.jupiter.api.Test)

Example 5 with Message

use of io.scalecube.cluster.transport.api.Message in project alibaba-rsocket-broker by alibaba.

the class RSocketBrokerManagerGossipImplTest method testGossipMessageEncoding.

@Test
public void testGossipMessageEncoding() throws Exception {
    Map<String, String> value = new HashMap<>();
    value.put("nick", "leijuan");
    Message message = Message.builder().correlationId("1").data(value).build();
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    messageCodec.serialize(message, bos);
    Message message1 = messageCodec.deserialize(new ByteArrayInputStream(bos.toByteArray()));
    Map<String, String> value2 = message1.data();
    Assertions.assertThat(value).containsEntry("nick", value2.get("nick"));
}
Also used : Message(io.scalecube.cluster.transport.api.Message) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

Message (io.scalecube.cluster.transport.api.Message)7 Address (io.scalecube.net.Address)5 Flux (reactor.core.publisher.Flux)5 Mono (reactor.core.publisher.Mono)5 Metrics (io.micrometer.core.instrument.Metrics)4 Cluster (io.scalecube.cluster.Cluster)4 ClusterImpl (io.scalecube.cluster.ClusterImpl)4 ClusterMessageHandler (io.scalecube.cluster.ClusterMessageHandler)4 Member (io.scalecube.cluster.Member)4 MembershipEvent (io.scalecube.cluster.membership.MembershipEvent)4 TcpTransportFactory (io.scalecube.transport.netty.tcp.TcpTransportFactory)4 java.util (java.util)4 Collectors (java.util.stream.Collectors)4 Stream (java.util.stream.Stream)4 Nullable (org.jetbrains.annotations.Nullable)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Sinks (reactor.core.publisher.Sinks)3 ServiceLocator (com.alibaba.rsocket.ServiceLocator)2 CloudEventImpl (com.alibaba.rsocket.cloudevents.CloudEventImpl)2