use of com.alibaba.rsocket.events.AppStatusEvent 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 com.alibaba.rsocket.events.AppStatusEvent in project alibaba-rsocket-broker by alibaba.
the class RSocketServicesPublishHook method onApplicationEvent.
@Override
public void onApplicationEvent(@NotNull ApplicationReadyEvent applicationReadyEvent) {
UpstreamCluster brokerCluster = upstreamManager.findBroker();
if (brokerCluster == null)
return;
// rsocket broker cluster logic
CloudEventImpl<AppStatusEvent> appStatusEventCloudEvent = RSocketCloudEventBuilder.builder(new AppStatusEvent(RSocketAppContext.ID, AppStatusEvent.STATUS_SERVING)).build();
LoadBalancedRSocket loadBalancedRSocket = brokerCluster.getLoadBalancedRSocket();
// ports update
ConfigurableEnvironment env = applicationReadyEvent.getApplicationContext().getEnvironment();
int serverPort = Integer.parseInt(env.getProperty("server.port", "0"));
if (serverPort == 0) {
if (RSocketAppContext.webPort > 0 || RSocketAppContext.managementPort > 0 || RSocketAppContext.rsocketPorts != null) {
PortsUpdateEvent portsUpdateEvent = new PortsUpdateEvent();
portsUpdateEvent.setAppId(RSocketAppContext.ID);
portsUpdateEvent.setWebPort(RSocketAppContext.webPort);
portsUpdateEvent.setManagementPort(RSocketAppContext.managementPort);
portsUpdateEvent.setRsocketPorts(RSocketAppContext.rsocketPorts);
CloudEventImpl<PortsUpdateEvent> portsUpdateCloudEvent = RSocketCloudEventBuilder.builder(portsUpdateEvent).build();
loadBalancedRSocket.fireCloudEventToUpstreamAll(portsUpdateCloudEvent).doOnSuccess(aVoid -> log.info(RsocketErrorCode.message("RST-301200", loadBalancedRSocket.getActiveUris()))).subscribe();
}
}
// app status
loadBalancedRSocket.fireCloudEventToUpstreamAll(appStatusEventCloudEvent).doOnSuccess(aVoid -> log.info(RsocketErrorCode.message("RST-301200", loadBalancedRSocket.getActiveUris()))).subscribe();
// service exposed
CloudEventImpl<ServicesExposedEvent> servicesExposedEventCloudEvent = rsocketRequesterSupport.servicesExposedEvent().get();
if (servicesExposedEventCloudEvent != null) {
loadBalancedRSocket.fireCloudEventToUpstreamAll(servicesExposedEventCloudEvent).doOnSuccess(aVoid -> {
String exposedServices = rsocketRequesterSupport.exposedServices().get().stream().map(ServiceLocator::getGsv).collect(Collectors.joining(","));
log.info(RsocketErrorCode.message("RST-301201", exposedServices, loadBalancedRSocket.getActiveUris()));
}).subscribe();
}
}
Aggregations