use of com.alibaba.rsocket.metadata.AppMetadata in project alibaba-rsocket-broker by alibaba.
the class RSocketBrokerHandlerRegistryImpl method onHandlerDisposed.
@Override
public void onHandlerDisposed(RSocketBrokerResponderHandler responderHandler) {
AppMetadata appMetadata = responderHandler.getAppMetadata();
responderHandlers.remove(responderHandler.getUuid());
connectionHandlers.remove(responderHandler.getId());
appHandlers.remove(appMetadata.getName(), responderHandler);
log.info(RsocketErrorCode.message("RST-500202"));
responderHandler.clean();
eventProcessor.tryEmitNext(appStatusEventCloudEvent(appMetadata, AppStatusEvent.STATUS_STOPPED));
this.appNotificationProcessor.tryEmitNext(RsocketErrorCode.message("RST-300204", appMetadata.getName(), appMetadata.getIp()));
if (appMetadata.getP2pServices() != null) {
routingSelector.unRegisterP2pServiceConsumer(responderHandler.getId(), appMetadata.getP2pServices());
}
}
use of com.alibaba.rsocket.metadata.AppMetadata 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;
}
use of com.alibaba.rsocket.metadata.AppMetadata in project alibaba-rsocket-broker by alibaba.
the class RSocketBrokerHandlerRegistryImpl method onHandlerRegistered.
@Override
public void onHandlerRegistered(RSocketBrokerResponderHandler responderHandler) {
AppMetadata appMetadata = responderHandler.getAppMetadata();
responderHandlers.put(appMetadata.getUuid(), responderHandler);
connectionHandlers.put(responderHandler.getId(), responderHandler);
appHandlers.put(appMetadata.getName(), responderHandler);
eventProcessor.tryEmitNext(appStatusEventCloudEvent(appMetadata, AppStatusEvent.STATUS_CONNECTED));
if (!rsocketBrokerManager.isStandAlone()) {
responderHandler.fireCloudEventToPeer(getBrokerClustersEvent(rsocketBrokerManager.currentBrokers(), appMetadata.getTopology())).subscribe();
}
this.appNotificationProcessor.tryEmitNext(RsocketErrorCode.message("RST-300203", appMetadata.getName(), appMetadata.getIp()));
// fire p2p service instances notification
if (appMetadata.getP2pServices() != null) {
routingSelector.registerP2pServiceConsumer(responderHandler.getId(), appMetadata.getP2pServices());
for (String p2pService : appMetadata.getP2pServices()) {
responderHandler.fireCloudEventToPeer(getServiceInstancesChangedEvent(p2pService)).subscribe();
}
}
}
use of com.alibaba.rsocket.metadata.AppMetadata in project alibaba-rsocket-broker by alibaba.
the class RSocketRequesterBySubBroker method getAppMetadata.
private AppMetadata getAppMetadata() {
System.out.println("app metadata");
// app metadata
AppMetadata appMetadata = new AppMetadata();
appMetadata.setUuid(RSocketAppContext.ID);
appMetadata.setName(appName);
appMetadata.setIp(NetworkUtil.LOCAL_IP);
appMetadata.setDevice("SpringBootApp");
appMetadata.setRsocketPorts(RSocketAppContext.rsocketPorts);
// brokers
appMetadata.setBrokers(properties.getUpstreamBrokers());
appMetadata.setTopology(properties.getTopology());
appMetadata.setRsocketPorts(RSocketAppContext.rsocketPorts);
// web port
appMetadata.setWebPort(Integer.parseInt(env.getProperty("server.port", "0")));
appMetadata.setManagementPort(appMetadata.getWebPort());
// management port
if (env.getProperty("management.server.port") != null) {
appMetadata.setManagementPort(Integer.parseInt(env.getProperty("management.server.port", "0")));
}
appMetadata.setManagementPort(Integer.parseInt(env.getProperty("management.server.port", "" + appMetadata.getWebPort())));
appMetadata.addMetadata("broker", "true");
return appMetadata;
}
use of com.alibaba.rsocket.metadata.AppMetadata in project alibaba-rsocket-broker by alibaba.
the class AppQueryController method query.
@GetMapping("/{appName}")
public Flux<Map<String, Object>> query(@PathVariable(name = "appName") String appName) {
List<Map<String, Object>> apps = new ArrayList<>();
Collection<RSocketBrokerResponderHandler> handlers = handlerRegistry.findByAppName(appName);
if (handlers != null) {
for (RSocketBrokerResponderHandler handler : handlers) {
Map<String, Object> app = new HashMap<>();
AppMetadata appMetadata = handler.getAppMetadata();
app.put("ip", appMetadata.getIp());
app.put("uuid", appMetadata.getUuid());
app.put("startedAt", appMetadata.getConnectedAt());
apps.add(app);
}
}
return Flux.fromIterable(apps);
}
Aggregations