use of com.alibaba.rsocket.upstream.ServiceInstancesChangedEvent 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());
}
Aggregations