Search in sources :

Example 1 with ServiceInstancesChangedEvent

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

Aggregations

ServiceLocator (com.alibaba.rsocket.ServiceLocator)1 ServiceInstancesChangedEvent (com.alibaba.rsocket.upstream.ServiceInstancesChangedEvent)1 ConcurrentHashMap (org.eclipse.collections.impl.map.mutable.ConcurrentHashMap)1 Nullable (org.jetbrains.annotations.Nullable)1