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();
}
}
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();
}
}
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);
}
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();
}
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"));
}
Aggregations