Search in sources :

Example 1 with LoadBalancedRSocket

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;
}
Also used : RSocketServiceHealth(com.alibaba.rsocket.health.RSocketServiceHealth) LoadBalancedRSocket(com.alibaba.rsocket.loadbalance.LoadBalancedRSocket) UpstreamCluster(com.alibaba.rsocket.upstream.UpstreamCluster) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation)

Example 2 with LoadBalancedRSocket

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);
}
Also used : HessianEncoder(com.alibaba.spring.boot.rsocket.hessian.HessianEncoder) HessianDecoder(com.alibaba.spring.boot.rsocket.hessian.HessianDecoder) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) LoadBalancedRSocket(com.alibaba.rsocket.loadbalance.LoadBalancedRSocket) Bean(org.springframework.context.annotation.Bean)

Example 3 with LoadBalancedRSocket

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);
}
Also used : HessianEncoder(com.alibaba.spring.boot.rsocket.hessian.HessianEncoder) HessianDecoder(com.alibaba.spring.boot.rsocket.hessian.HessianDecoder) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) LoadBalancedRSocket(com.alibaba.rsocket.loadbalance.LoadBalancedRSocket) Bean(org.springframework.context.annotation.Bean)

Example 4 with LoadBalancedRSocket

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();
    }
}
Also used : Logger(org.slf4j.Logger) PortsUpdateEvent(com.alibaba.rsocket.events.PortsUpdateEvent) UpstreamCluster(com.alibaba.rsocket.upstream.UpstreamCluster) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) RSocketAppContext(com.alibaba.rsocket.RSocketAppContext) RSocketRequesterSupport(com.alibaba.rsocket.RSocketRequesterSupport) RsocketErrorCode(com.alibaba.rsocket.observability.RsocketErrorCode) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ApplicationListener(org.springframework.context.ApplicationListener) Collectors(java.util.stream.Collectors) LoadBalancedRSocket(com.alibaba.rsocket.loadbalance.LoadBalancedRSocket) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) ServicesExposedEvent(com.alibaba.rsocket.events.ServicesExposedEvent) CloudEventImpl(com.alibaba.rsocket.cloudevents.CloudEventImpl) UpstreamManager(com.alibaba.rsocket.upstream.UpstreamManager) RSocketCloudEventBuilder(com.alibaba.rsocket.cloudevents.RSocketCloudEventBuilder) NotNull(org.jetbrains.annotations.NotNull) ServiceLocator(com.alibaba.rsocket.ServiceLocator) AppStatusEvent(com.alibaba.rsocket.events.AppStatusEvent) PortsUpdateEvent(com.alibaba.rsocket.events.PortsUpdateEvent) UpstreamCluster(com.alibaba.rsocket.upstream.UpstreamCluster) ServiceLocator(com.alibaba.rsocket.ServiceLocator) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) LoadBalancedRSocket(com.alibaba.rsocket.loadbalance.LoadBalancedRSocket) ServicesExposedEvent(com.alibaba.rsocket.events.ServicesExposedEvent) AppStatusEvent(com.alibaba.rsocket.events.AppStatusEvent)

Example 5 with LoadBalancedRSocket

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);
}
Also used : HessianEncoder(com.alibaba.spring.boot.rsocket.hessian.HessianEncoder) HessianDecoder(com.alibaba.spring.boot.rsocket.hessian.HessianDecoder) RSocketStrategies(org.springframework.messaging.rsocket.RSocketStrategies) LoadBalancedRSocket(com.alibaba.rsocket.loadbalance.LoadBalancedRSocket) Bean(org.springframework.context.annotation.Bean)

Aggregations

LoadBalancedRSocket (com.alibaba.rsocket.loadbalance.LoadBalancedRSocket)7 HessianDecoder (com.alibaba.spring.boot.rsocket.hessian.HessianDecoder)3 HessianEncoder (com.alibaba.spring.boot.rsocket.hessian.HessianEncoder)3 Bean (org.springframework.context.annotation.Bean)3 RSocketStrategies (org.springframework.messaging.rsocket.RSocketStrategies)3 UpstreamCluster (com.alibaba.rsocket.upstream.UpstreamCluster)2 RSocketAppContext (com.alibaba.rsocket.RSocketAppContext)1 RSocketRequesterSupport (com.alibaba.rsocket.RSocketRequesterSupport)1 ServiceLocator (com.alibaba.rsocket.ServiceLocator)1 CloudEventImpl (com.alibaba.rsocket.cloudevents.CloudEventImpl)1 RSocketCloudEventBuilder (com.alibaba.rsocket.cloudevents.RSocketCloudEventBuilder)1 AppStatusEvent (com.alibaba.rsocket.events.AppStatusEvent)1 PortsUpdateEvent (com.alibaba.rsocket.events.PortsUpdateEvent)1 ServicesExposedEvent (com.alibaba.rsocket.events.ServicesExposedEvent)1 RSocketServiceHealth (com.alibaba.rsocket.health.RSocketServiceHealth)1 RsocketErrorCode (com.alibaba.rsocket.observability.RsocketErrorCode)1 UpstreamManager (com.alibaba.rsocket.upstream.UpstreamManager)1 Collectors (java.util.stream.Collectors)1 NotNull (org.jetbrains.annotations.NotNull)1 Logger (org.slf4j.Logger)1