Search in sources :

Example 1 with RSocketServiceInstance

use of com.alibaba.rsocket.discovery.RSocketServiceInstance in project alibaba-rsocket-broker by alibaba.

the class DiscoveryServiceImpl method findServiceInstances.

@NotNull
private Flux<RSocketServiceInstance> findServiceInstances(String serviceId) {
    Integer serviceHashCode = ServiceLocator.serviceHashCode(serviceId);
    Collection<Integer> instanceIdList = routingSelector.findHandlers(serviceHashCode);
    if (instanceIdList.isEmpty()) {
        return findServiceInstancesByAppName(serviceId);
    }
    List<RSocketServiceInstance> serviceInstances = new ArrayList<>();
    for (Integer handlerId : instanceIdList) {
        RSocketBrokerResponderHandler handler = handlerRegistry.findById(handlerId);
        if (handler != null) {
            serviceInstances.add(constructServiceInstance(handler));
        }
    }
    return Flux.fromIterable(serviceInstances);
}
Also used : RSocketBrokerResponderHandler(com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler) RSocketServiceInstance(com.alibaba.rsocket.discovery.RSocketServiceInstance) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with RSocketServiceInstance

use of com.alibaba.rsocket.discovery.RSocketServiceInstance in project alibaba-rsocket-broker by alibaba.

the class DiscoveryServiceImpl method constructServiceInstance.

@NotNull
private RSocketServiceInstance constructServiceInstance(RSocketBrokerResponderHandler handler) {
    AppMetadata appMetadata = handler.getAppMetadata();
    RSocketServiceInstance serviceInstance = new RSocketServiceInstance();
    serviceInstance.setInstanceId(appMetadata.getUuid());
    serviceInstance.setServiceId(appMetadata.getName());
    serviceInstance.setHost(appMetadata.getIp());
    Map<Integer, String> rsocketPorts = appMetadata.getRsocketPorts();
    if (rsocketPorts != null && !rsocketPorts.isEmpty()) {
        Map.Entry<Integer, String> entry = rsocketPorts.entrySet().stream().findFirst().get();
        try {
            serviceInstance.setPort(entry.getKey());
            serviceInstance.setSchema(entry.getValue());
            serviceInstance.setUri(entry.getValue() + "://" + appMetadata.getIp() + ":" + entry.getKey());
        } catch (Exception ignore) {
        }
    }
    serviceInstance.setMetadata(appMetadata.getMetadata());
    return serviceInstance;
}
Also used : RSocketServiceInstance(com.alibaba.rsocket.discovery.RSocketServiceInstance) AppMetadata(com.alibaba.rsocket.metadata.AppMetadata) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RSocketServiceInstance (com.alibaba.rsocket.discovery.RSocketServiceInstance)2 NotNull (org.jetbrains.annotations.NotNull)2 AppMetadata (com.alibaba.rsocket.metadata.AppMetadata)1 RSocketBrokerResponderHandler (com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1