use of com.alibaba.rsocket.cloudevents.CloudEventImpl in project alibaba-rsocket-broker by alibaba.
the class RSocketBrokerHandlerRegistryImpl method getBrokerClustersEvent.
private CloudEventImpl<UpstreamClusterChangedEvent> getBrokerClustersEvent(Collection<RSocketBroker> rSocketBrokers, String topology) {
List<String> uris;
if ("internet".equals(topology)) {
uris = rSocketBrokers.stream().filter(rsocketBroker -> rsocketBroker.isActive() && rsocketBroker.getExternalDomain() != null).map(RSocketBroker::getAliasUrl).collect(Collectors.toList());
} else {
uris = rSocketBrokers.stream().filter(RSocketBroker::isActive).map(RSocketBroker::getUrl).collect(Collectors.toList());
}
UpstreamClusterChangedEvent upstreamClusterChangedEvent = new UpstreamClusterChangedEvent();
upstreamClusterChangedEvent.setGroup("");
upstreamClusterChangedEvent.setInterfaceName("*");
upstreamClusterChangedEvent.setVersion("");
upstreamClusterChangedEvent.setUris(uris);
// passing in the given attributes
return RSocketCloudEventBuilder.builder(upstreamClusterChangedEvent).withDataschema(URI.create("rsocket:event:com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent")).withSource(BrokerAppContext.identity()).build();
}
use of com.alibaba.rsocket.cloudevents.CloudEventImpl 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();
}
}
use of com.alibaba.rsocket.cloudevents.CloudEventImpl in project alibaba-rsocket-broker by alibaba.
the class RSocketAutoConfiguration method rsocketResponderHandlerFactoryWithZipkin.
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(type = "brave.Tracing")
public RSocketResponderHandlerFactory rsocketResponderHandlerFactoryWithZipkin(@Autowired LocalReactiveServiceCaller serviceCaller, @Autowired @Qualifier("reactiveCloudEventProcessor") TopicProcessor<CloudEventImpl> eventProcessor) {
return (setupPayload, requester) -> Mono.fromCallable(() -> {
RSocketResponderHandler responderHandler = new RSocketResponderHandler(serviceCaller, eventProcessor, requester, setupPayload);
Tracing tracing = applicationContext.getBean(Tracing.class);
responderHandler.setTracer(tracing.tracer());
return responderHandler;
});
}
use of com.alibaba.rsocket.cloudevents.CloudEventImpl in project alibaba-rsocket-broker by alibaba.
the class RSocketBrokerClient method removeService.
public void removeService(String serviceName, Class<?> serviceInterface) {
ServiceLocator targetService = new ServiceLocator("", serviceName, "");
CloudEventImpl<ServicesHiddenEvent> cloudEvent = ServicesHiddenEvent.convertServicesToCloudEvent(Collections.singletonList(targetService));
upstreamManager.findBroker().getLoadBalancedRSocket().fireCloudEventToUpstreamAll(cloudEvent).doOnSuccess(unused -> {
this.serviceCaller.removeProvider("", serviceName, "", serviceInterface);
}).subscribe();
}
Aggregations