use of com.alibaba.rsocket.loadbalance.LoadBalancedRSocket in project alibaba-rsocket-broker by alibaba.
the class RSocketEndpoint method info.
@ReadOperation
public Map<String, Object> info() {
Map<String, Object> info = new HashMap<>();
info.put("id", RSocketAppContext.ID);
info.put("serviceStatus", AppStatusEvent.statusText(this.rsocketServiceStatus));
if (this.serviceProvider) {
info.put("published", rsocketRequesterSupport.exposedServices().get());
}
if (!RSocketRemoteServiceBuilder.CONSUMED_SERVICES.isEmpty()) {
info.put("subscribed", rsocketRequesterSupport.subscribedServices().get().stream().filter(serviceLocator -> !RSocketServiceHealth.class.getCanonicalName().equals(serviceLocator.getService())).collect(Collectors.toList()));
}
Collection<UpstreamCluster> upstreamClusters = upstreamManager.findAllClusters();
if (!upstreamClusters.isEmpty()) {
info.put("upstreams", upstreamClusters.stream().map(upstreamCluster -> {
Map<String, Object> temp = new HashMap<>();
temp.put("service", upstreamCluster.getServiceId());
temp.put("uris", upstreamCluster.getUris());
LoadBalancedRSocket loadBalancedRSocket = upstreamCluster.getLoadBalancedRSocket();
temp.put("activeUris", loadBalancedRSocket.getActiveSockets().keySet());
if (!loadBalancedRSocket.getUnHealthyUriSet().isEmpty()) {
temp.put("unHealthyUris", loadBalancedRSocket.getUnHealthyUriSet());
}
temp.put("lastRefreshTimeStamp", new Date(loadBalancedRSocket.getLastRefreshTimeStamp()));
temp.put("lastHealthCheckTimeStamp", new Date(loadBalancedRSocket.getLastHealthCheckTimeStamp()));
return temp;
}).collect(Collectors.toList()));
}
UpstreamCluster brokerCluster = upstreamManager.findClusterByServiceId("*");
if (brokerCluster != null) {
info.put("brokers", brokerCluster.getUris());
}
if (properties.getMetadata() != null && !properties.getMetadata().isEmpty()) {
info.put("metadata", properties.getMetadata());
}
if (!offlineServices.isEmpty()) {
info.put("offlineServices", offlineServices);
}
return info;
}
use of com.alibaba.rsocket.loadbalance.LoadBalancedRSocket in project alibaba-broker-example-parent by linux-china.
the class ServiceConsumeConfiguration method rsocketRequester.
@Bean
public RSocketRequester rsocketRequester(UpstreamManager upstreamManager) {
LoadBalancedRSocket loadBalancedRSocket = upstreamManager.findBroker().getLoadBalancedRSocket();
RSocketStrategies rSocketStrategies = RSocketStrategies.builder().encoder(new HessianEncoder()).decoder(new HessianDecoder()).build();
return RSocketRequester.wrap(loadBalancedRSocket, MimeType.valueOf("application/x-hessian"), MimeType.valueOf("message/x.rsocket.composite-metadata.v0"), rSocketStrategies);
}
use of com.alibaba.rsocket.loadbalance.LoadBalancedRSocket in project alibaba-broker-kotlin-example by alibaba-rsocket-broker.
the class ServiceConsumeConfiguration method rsocketRequester.
@Bean
public RSocketRequester rsocketRequester(UpstreamManager upstreamManager) {
LoadBalancedRSocket loadBalancedRSocket = upstreamManager.findBroker().getLoadBalancedRSocket();
RSocketStrategies rSocketStrategies = RSocketStrategies.builder().encoder(new HessianEncoder()).decoder(new HessianDecoder()).build();
return RSocketRequester.wrap(loadBalancedRSocket, MimeType.valueOf("application/x-hessian"), MimeType.valueOf("message/x.rsocket.composite-metadata.v0"), rSocketStrategies);
}
use of com.alibaba.rsocket.loadbalance.LoadBalancedRSocket 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.loadbalance.LoadBalancedRSocket in project alibaba-rsocket-broker by alibaba.
the class ServiceConsumeConfiguration method rsocketRequester.
@Bean
public RSocketRequester rsocketRequester(UpstreamManager upstreamManager) {
LoadBalancedRSocket loadBalancedRSocket = upstreamManager.findBroker().getLoadBalancedRSocket();
RSocketStrategies rSocketStrategies = RSocketStrategies.builder().encoder(new HessianEncoder()).decoder(new HessianDecoder()).build();
return RSocketRequester.wrap(loadBalancedRSocket, MimeType.valueOf("application/x-hessian"), MimeType.valueOf("message/x.rsocket.composite-metadata.v0"), rSocketStrategies);
}
Aggregations