Search in sources :

Example 11 with ServiceLocator

use of com.alibaba.rsocket.ServiceLocator in project alibaba-rsocket-broker by alibaba.

the class ServiceQueryController method queryDefinition.

@GetMapping(value = "/definition/{serviceName}")
public Mono<String> queryDefinition(@PathVariable(name = "serviceName") String serviceName) {
    Integer handler = routingSelector.findHandler(new ServiceLocator("", serviceName, "").getId());
    if (handler != null) {
        RSocketBrokerResponderHandler brokerResponderHandler = brokerHandlerRegistry.findById(handler);
        if (brokerResponderHandler != null) {
            GSVRoutingMetadata routingMetadata = new GSVRoutingMetadata("", ReactiveServiceDiscovery.class.getCanonicalName() + ".findServiceByFullName", "");
            RSocketCompositeMetadata compositeMetadata = RSocketCompositeMetadata.from(routingMetadata, jsonMetaEncoding);
            ByteBuf bodyBuf = Unpooled.wrappedBuffer(("[\"" + serviceName + "\"]").getBytes(StandardCharsets.UTF_8));
            return brokerResponderHandler.getPeerRsocket().requestResponse(ByteBufPayload.create(bodyBuf, compositeMetadata.getContent())).map(Payload::getDataUtf8);
        }
    }
    return Mono.error(new Exception(RsocketErrorCode.message("RST-900404", serviceName)));
}
Also used : ServiceLocator(com.alibaba.rsocket.ServiceLocator) RSocketBrokerResponderHandler(com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler) RSocketCompositeMetadata(com.alibaba.rsocket.metadata.RSocketCompositeMetadata) GSVRoutingMetadata(com.alibaba.rsocket.metadata.GSVRoutingMetadata) Payload(io.rsocket.Payload) ByteBufPayload(io.rsocket.util.ByteBufPayload) ByteBuf(io.netty.buffer.ByteBuf) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 12 with ServiceLocator

use of com.alibaba.rsocket.ServiceLocator in project alibaba-rsocket-broker by alibaba.

the class RSocketBrokerHandlerRegistryImpl method getServiceInstancesChangedEvent.

@Nullable
private CloudEventImpl<ServiceInstancesChangedEvent> getServiceInstancesChangedEvent(String serviceId) {
    ServiceLocator serviceLocator = new ServiceLocator(serviceId);
    Collection<Integer> instanceIdList = routingSelector.findHandlers(serviceLocator.getId());
    ServiceInstancesChangedEvent event = new ServiceInstancesChangedEvent();
    event.setGroup(serviceLocator.getGroup());
    event.setService(serviceLocator.getService());
    event.setVersion(serviceLocator.getVersion());
    event.setType(0);
    List<String> uris = new ArrayList<>();
    for (Integer handlerId : instanceIdList) {
        RSocketBrokerResponderHandler handler = this.findById(handlerId);
        if (handler != null) {
            Map<Integer, String> rsocketPorts = handler.getAppMetadata().getRsocketPorts();
            if (rsocketPorts != null && !rsocketPorts.isEmpty()) {
                Map.Entry<Integer, String> entry = rsocketPorts.entrySet().stream().findFirst().get();
                String uri = entry.getValue() + "://" + handler.getAppMetadata().getIp() + ":" + entry.getKey();
                uris.add(uri);
            }
        }
    }
    event.setUris(uris);
    return event.toCloudEvent(BrokerAppContext.identity());
}
Also used : ServiceLocator(com.alibaba.rsocket.ServiceLocator) ServiceInstancesChangedEvent(com.alibaba.rsocket.upstream.ServiceInstancesChangedEvent) ConcurrentHashMap(org.eclipse.collections.impl.map.mutable.ConcurrentHashMap) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with ServiceLocator

use of com.alibaba.rsocket.ServiceLocator 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

ServiceLocator (com.alibaba.rsocket.ServiceLocator)13 CloudEventImpl (com.alibaba.rsocket.cloudevents.CloudEventImpl)3 ServicesExposedEvent (com.alibaba.rsocket.events.ServicesExposedEvent)3 Collectors (java.util.stream.Collectors)3 RSocketAppContext (com.alibaba.rsocket.RSocketAppContext)2 RSocketRequesterSupport (com.alibaba.rsocket.RSocketRequesterSupport)2 RSocketServiceHealth (com.alibaba.rsocket.health.RSocketServiceHealth)2 RSocketRemoteServiceBuilder (com.alibaba.rsocket.invocation.RSocketRemoteServiceBuilder)2 RsocketErrorCode (com.alibaba.rsocket.observability.RsocketErrorCode)2 UpstreamCluster (com.alibaba.rsocket.upstream.UpstreamCluster)2 UpstreamManager (com.alibaba.rsocket.upstream.UpstreamManager)2 Payload (io.rsocket.Payload)2 ByteBufPayload (io.rsocket.util.ByteBufPayload)2 NotNull (org.jetbrains.annotations.NotNull)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 RSocketService (com.alibaba.rsocket.RSocketService)1 RSocketCloudEventBuilder (com.alibaba.rsocket.cloudevents.RSocketCloudEventBuilder)1 AppStatusEvent (com.alibaba.rsocket.events.AppStatusEvent)1 CloudEventsProcessor (com.alibaba.rsocket.events.CloudEventsProcessor)1