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