use of com.alibaba.rsocket.ServiceLocator in project alibaba-rsocket-broker by alibaba.
the class RSocketRequesterSupportImpl method exposedServices.
@Override
public Supplier<Set<ServiceLocator>> exposedServices() {
return () -> {
return applicationContext.getBeansWithAnnotation(RSocketService.class).values().stream().filter(bean -> !(bean instanceof RSocketServiceHealth || bean instanceof MetricsService)).map(o -> {
Class<?> managedBeanClass = AopUtils.isAopProxy(o) ? AopUtils.getTargetClass(o) : o.getClass();
RSocketService rsocketService = AnnotationUtils.findAnnotation(managedBeanClass, RSocketService.class);
// noinspection ConstantConditions
String serviceName = rsocketService.serviceInterface().getCanonicalName();
if (!rsocketService.name().isEmpty()) {
serviceName = rsocketService.name();
}
String group = properties.getGroup();
if (group == null || group.isEmpty()) {
group = rsocketService.group();
}
String version = properties.getVersion();
if (version == null || version.isEmpty()) {
version = rsocketService.version();
}
return new ServiceLocator(group, serviceName, version, rsocketService.tags());
}).collect(Collectors.toSet());
};
}
use of com.alibaba.rsocket.ServiceLocator in project alibaba-rsocket-broker by alibaba.
the class RSocketServicesPublishHook method onApplicationEvent.
@Override
public void onApplicationEvent(@NotNull ApplicationReadyEvent applicationReadyEvent) {
UpstreamCluster brokerCluster = upstreamManager.findBroker();
if (brokerCluster == null)
return;
// rsocket broker cluster logic
CloudEventImpl<AppStatusEvent> appStatusEventCloudEvent = RSocketCloudEventBuilder.builder(new AppStatusEvent(RSocketAppContext.ID, AppStatusEvent.STATUS_SERVING)).build();
LoadBalancedRSocket loadBalancedRSocket = brokerCluster.getLoadBalancedRSocket();
// ports update
ConfigurableEnvironment env = applicationReadyEvent.getApplicationContext().getEnvironment();
int serverPort = Integer.parseInt(env.getProperty("server.port", "0"));
if (serverPort == 0) {
if (RSocketAppContext.webPort > 0 || RSocketAppContext.managementPort > 0 || RSocketAppContext.rsocketPorts != null) {
PortsUpdateEvent portsUpdateEvent = new PortsUpdateEvent();
portsUpdateEvent.setAppId(RSocketAppContext.ID);
portsUpdateEvent.setWebPort(RSocketAppContext.webPort);
portsUpdateEvent.setManagementPort(RSocketAppContext.managementPort);
portsUpdateEvent.setRsocketPorts(RSocketAppContext.rsocketPorts);
CloudEventImpl<PortsUpdateEvent> portsUpdateCloudEvent = RSocketCloudEventBuilder.builder(portsUpdateEvent).build();
loadBalancedRSocket.fireCloudEventToUpstreamAll(portsUpdateCloudEvent).doOnSuccess(aVoid -> log.info(RsocketErrorCode.message("RST-301200", loadBalancedRSocket.getActiveUris()))).subscribe();
}
}
// app status
loadBalancedRSocket.fireCloudEventToUpstreamAll(appStatusEventCloudEvent).doOnSuccess(aVoid -> log.info(RsocketErrorCode.message("RST-301200", loadBalancedRSocket.getActiveUris()))).subscribe();
// service exposed
CloudEventImpl<ServicesExposedEvent> servicesExposedEventCloudEvent = rsocketRequesterSupport.servicesExposedEvent().get();
if (servicesExposedEventCloudEvent != null) {
loadBalancedRSocket.fireCloudEventToUpstreamAll(servicesExposedEventCloudEvent).doOnSuccess(aVoid -> {
String exposedServices = rsocketRequesterSupport.exposedServices().get().stream().map(ServiceLocator::getGsv).collect(Collectors.joining(","));
log.info(RsocketErrorCode.message("RST-301201", exposedServices, loadBalancedRSocket.getActiveUris()));
}).subscribe();
}
}
use of com.alibaba.rsocket.ServiceLocator in project alibaba-rsocket-broker by alibaba.
the class ServicesHiddenEvent method convertServicesToCloudEvent.
public static CloudEventImpl<ServicesHiddenEvent> convertServicesToCloudEvent(Collection<ServiceLocator> serviceLocators) {
ServicesHiddenEvent servicesHiddenEvent = new ServicesHiddenEvent();
for (ServiceLocator serviceLocator : serviceLocators) {
servicesHiddenEvent.addService(serviceLocator);
}
servicesHiddenEvent.setAppId(RSocketAppContext.ID);
return RSocketCloudEventBuilder.builder(servicesHiddenEvent).build();
}
use of com.alibaba.rsocket.ServiceLocator in project alibaba-rsocket-broker by alibaba.
the class RSocketRemoteServiceBuilder method buildByteBuddyProxy.
public T buildByteBuddyProxy() {
CONSUMED_SERVICES.add(new ServiceLocator(group, service, version));
RSocketRequesterRpcProxy proxy = getRequesterProxy();
return ByteBuddyUtils.build(this.serviceInterface, proxy);
}
use of com.alibaba.rsocket.ServiceLocator in project alibaba-rsocket-broker by alibaba.
the class ServiceRoutingSelectorImplTest method testOperation.
@Test
public void testOperation() {
Integer instanceId = 1;
Set<ServiceLocator> services = new HashSet<>();
services.add(new ServiceLocator("", "1", ""));
services.add(new ServiceLocator("", "2", ""));
services.add(new ServiceLocator("", "3", ""));
routingSelector.register(instanceId, services);
Assertions.assertTrue(routingSelector.containInstance(instanceId));
Assertions.assertTrue(routingSelector.containService(MurmurHash3.hash32("1")));
Assertions.assertNotNull(routingSelector.findHandler(MurmurHash3.hash32("1")));
Assertions.assertNull(routingSelector.findHandler(MurmurHash3.hash32("4")));
Assertions.assertEquals(1, routingSelector.getInstanceCount(MurmurHash3.hash32("1")));
routingSelector.deregister(instanceId);
Assertions.assertNull(routingSelector.findHandler(MurmurHash3.hash32("1")));
}
Aggregations