Search in sources :

Example 1 with CloudEventImpl

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();
}
Also used : Sinks(reactor.core.publisher.Sinks) BearerTokenMetadata(com.alibaba.rsocket.metadata.BearerTokenMetadata) java.util(java.util) ConcurrentHashMap(org.eclipse.collections.impl.map.mutable.ConcurrentHashMap) Multimap(org.eclipse.collections.api.multimap.Multimap) LoggerFactory(org.slf4j.LoggerFactory) BrokerAppContext(com.alibaba.spring.boot.rsocket.broker.BrokerAppContext) RejectedSetupException(io.rsocket.exceptions.RejectedSetupException) RSocketAppPrincipal(com.alibaba.spring.boot.rsocket.broker.security.RSocketAppPrincipal) FastListMultimap(org.eclipse.collections.impl.multimap.list.FastListMultimap) Metrics(io.micrometer.core.instrument.Metrics) ApplicationErrorException(io.rsocket.exceptions.ApplicationErrorException) AuthenticationService(com.alibaba.spring.boot.rsocket.broker.security.AuthenticationService) RSocket(io.rsocket.RSocket) CloudEventImpl(com.alibaba.rsocket.cloudevents.CloudEventImpl) Duration(java.time.Duration) RSocketBroker(com.alibaba.spring.boot.rsocket.broker.cluster.RSocketBroker) Schedulers(reactor.core.scheduler.Schedulers) RSocketFilterChain(com.alibaba.rsocket.route.RSocketFilterChain) URI(java.net.URI) UpstreamClusterChangedEvent(com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent) DoubleFunction(org.eclipse.collections.api.block.function.primitive.DoubleFunction) AppStatusEvent(com.alibaba.rsocket.events.AppStatusEvent) RSocketBrokerManager(com.alibaba.spring.boot.rsocket.broker.cluster.RSocketBrokerManager) ServiceMeshInspector(com.alibaba.spring.boot.rsocket.broker.route.ServiceMeshInspector) RSocketMimeType(com.alibaba.rsocket.metadata.RSocketMimeType) Logger(org.slf4j.Logger) RsocketErrorCode(com.alibaba.rsocket.observability.RsocketErrorCode) Mono(reactor.core.publisher.Mono) ServiceRoutingSelector(com.alibaba.spring.boot.rsocket.broker.route.ServiceRoutingSelector) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) ServiceInstancesChangedEvent(com.alibaba.rsocket.upstream.ServiceInstancesChangedEvent) Nullable(org.jetbrains.annotations.Nullable) Flux(reactor.core.publisher.Flux) AppMetadata(com.alibaba.rsocket.metadata.AppMetadata) MurmurHash3(com.alibaba.rsocket.utils.MurmurHash3) ConnectionSetupPayload(io.rsocket.ConnectionSetupPayload) RSocketCloudEventBuilder(com.alibaba.rsocket.cloudevents.RSocketCloudEventBuilder) LocalReactiveServiceCaller(com.alibaba.rsocket.rpc.LocalReactiveServiceCaller) NotNull(org.jetbrains.annotations.NotNull) ServiceLocator(com.alibaba.rsocket.ServiceLocator) JwtPrincipal(com.alibaba.spring.boot.rsocket.broker.security.JwtPrincipal) RSocketBroker(com.alibaba.spring.boot.rsocket.broker.cluster.RSocketBroker) UpstreamClusterChangedEvent(com.alibaba.rsocket.upstream.UpstreamClusterChangedEvent)

Example 2 with CloudEventImpl

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();
    }
}
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 3 with CloudEventImpl

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;
    });
}
Also used : RSocketServiceHealth(com.alibaba.rsocket.health.RSocketServiceHealth) RSocketAppContext(com.alibaba.rsocket.RSocketAppContext) RSocketRequesterSupport(com.alibaba.rsocket.RSocketRequesterSupport) TopicProcessor(reactor.extra.processor.TopicProcessor) JwtTokenNotFoundException(com.alibaba.spring.boot.rsocket.upstream.JwtTokenNotFoundException) Autowired(org.springframework.beans.factory.annotation.Autowired) RSocketServicesPublishHook(com.alibaba.spring.boot.rsocket.responder.RSocketServicesPublishHook) RSocketServiceAnnotationProcessor(com.alibaba.spring.boot.rsocket.responder.invocation.RSocketServiceAnnotationProcessor) Value(org.springframework.beans.factory.annotation.Value) RSocketResponderHandler(com.alibaba.rsocket.rpc.RSocketResponderHandler) ObjectProvider(org.springframework.beans.factory.ObjectProvider) CloudEventImpl(com.alibaba.rsocket.cloudevents.CloudEventImpl) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Qualifier(org.springframework.beans.factory.annotation.Qualifier) WebServerInitializedEvent(org.springframework.boot.web.context.WebServerInitializedEvent) MetricsService(com.alibaba.rsocket.observability.MetricsService) RSocketRequesterSupportCustomizer(com.alibaba.spring.boot.rsocket.upstream.RSocketRequesterSupportCustomizer) Tracing(brave.Tracing) org.springframework.boot.autoconfigure.condition(org.springframework.boot.autoconfigure.condition) UpstreamCluster(com.alibaba.rsocket.upstream.UpstreamCluster) Mono(reactor.core.publisher.Mono) RSocketResponderHandlerFactory(com.alibaba.rsocket.listen.RSocketResponderHandlerFactory) SmartLifecycleUpstreamManagerImpl(com.alibaba.spring.boot.rsocket.upstream.SmartLifecycleUpstreamManagerImpl) ApplicationListener(org.springframework.context.ApplicationListener) CloudEventsProcessor(com.alibaba.rsocket.events.CloudEventsProcessor) SocketAcceptor(io.rsocket.SocketAcceptor) ServiceInstancesChangedEventConsumer(com.alibaba.rsocket.upstream.ServiceInstancesChangedEventConsumer) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) MetricsServicePrometheusImpl(com.alibaba.spring.boot.rsocket.observability.MetricsServicePrometheusImpl) RoutingEndpoint(com.alibaba.rsocket.route.RoutingEndpoint) Configuration(org.springframework.context.annotation.Configuration) RSocketServiceHealthImpl(com.alibaba.spring.boot.rsocket.health.RSocketServiceHealthImpl) CloudEventsConsumer(com.alibaba.rsocket.events.CloudEventsConsumer) UpstreamClusterChangedEventConsumer(com.alibaba.rsocket.upstream.UpstreamClusterChangedEventConsumer) Environment(org.springframework.core.env.Environment) PrometheusMeterRegistry(io.micrometer.prometheus.PrometheusMeterRegistry) UpstreamManager(com.alibaba.rsocket.upstream.UpstreamManager) Bean(org.springframework.context.annotation.Bean) LocalReactiveServiceCaller(com.alibaba.rsocket.rpc.LocalReactiveServiceCaller) RSocketRequesterSupportBuilderImpl(com.alibaba.spring.boot.rsocket.upstream.RSocketRequesterSupportBuilderImpl) RSocketResponderHandler(com.alibaba.rsocket.rpc.RSocketResponderHandler) Tracing(brave.Tracing) Bean(org.springframework.context.annotation.Bean)

Example 4 with CloudEventImpl

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();
}
Also used : ServiceLocator(com.alibaba.rsocket.ServiceLocator) RSocketMimeType(com.alibaba.rsocket.metadata.RSocketMimeType) RSocketServiceHealth(com.alibaba.rsocket.health.RSocketServiceHealth) Logger(org.slf4j.Logger) UpstreamCluster(com.alibaba.rsocket.upstream.UpstreamCluster) RsocketErrorCode(com.alibaba.rsocket.observability.RsocketErrorCode) LoggerFactory(org.slf4j.LoggerFactory) TopicProcessor(reactor.extra.processor.TopicProcessor) UpstreamManagerImpl(com.alibaba.rsocket.upstream.UpstreamManagerImpl) Mono(reactor.core.publisher.Mono) CloudEventsProcessor(com.alibaba.rsocket.events.CloudEventsProcessor) Collectors(java.util.stream.Collectors) ServicesHiddenEvent(com.alibaba.rsocket.events.ServicesHiddenEvent) ArrayList(java.util.ArrayList) List(java.util.List) RSocketRemoteServiceBuilder(com.alibaba.rsocket.invocation.RSocketRemoteServiceBuilder) UpstreamClusterChangedEventConsumer(com.alibaba.rsocket.upstream.UpstreamClusterChangedEventConsumer) ServicesExposedEvent(com.alibaba.rsocket.events.ServicesExposedEvent) CloudEventImpl(com.alibaba.rsocket.cloudevents.CloudEventImpl) Map(java.util.Map) UpstreamManager(com.alibaba.rsocket.upstream.UpstreamManager) LocalReactiveServiceCaller(com.alibaba.rsocket.rpc.LocalReactiveServiceCaller) Collections(java.util.Collections) ServiceLocator(com.alibaba.rsocket.ServiceLocator) ServicesHiddenEvent(com.alibaba.rsocket.events.ServicesHiddenEvent)

Aggregations

CloudEventImpl (com.alibaba.rsocket.cloudevents.CloudEventImpl)4 Collectors (java.util.stream.Collectors)4 ServiceLocator (com.alibaba.rsocket.ServiceLocator)3 RsocketErrorCode (com.alibaba.rsocket.observability.RsocketErrorCode)3 LocalReactiveServiceCaller (com.alibaba.rsocket.rpc.LocalReactiveServiceCaller)3 UpstreamCluster (com.alibaba.rsocket.upstream.UpstreamCluster)3 UpstreamManager (com.alibaba.rsocket.upstream.UpstreamManager)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 RSocketAppContext (com.alibaba.rsocket.RSocketAppContext)2 RSocketRequesterSupport (com.alibaba.rsocket.RSocketRequesterSupport)2 RSocketCloudEventBuilder (com.alibaba.rsocket.cloudevents.RSocketCloudEventBuilder)2 AppStatusEvent (com.alibaba.rsocket.events.AppStatusEvent)2 CloudEventsProcessor (com.alibaba.rsocket.events.CloudEventsProcessor)2 ServicesExposedEvent (com.alibaba.rsocket.events.ServicesExposedEvent)2 RSocketServiceHealth (com.alibaba.rsocket.health.RSocketServiceHealth)2 RSocketMimeType (com.alibaba.rsocket.metadata.RSocketMimeType)2 UpstreamClusterChangedEventConsumer (com.alibaba.rsocket.upstream.UpstreamClusterChangedEventConsumer)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 ApplicationListener (org.springframework.context.ApplicationListener)2