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);
}
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;
}
Aggregations