Search in sources :

Example 1 with AppMetadata

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());
    }
}
Also used : AppMetadata(com.alibaba.rsocket.metadata.AppMetadata)

Example 2 with AppMetadata

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;
}
Also used : RSocketServiceInstance(com.alibaba.rsocket.discovery.RSocketServiceInstance) AppMetadata(com.alibaba.rsocket.metadata.AppMetadata) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with AppMetadata

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();
        }
    }
}
Also used : AppMetadata(com.alibaba.rsocket.metadata.AppMetadata)

Example 4 with AppMetadata

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;
}
Also used : AppMetadata(com.alibaba.rsocket.metadata.AppMetadata)

Example 5 with 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);
}
Also used : RSocketBrokerResponderHandler(com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler) AppMetadata(com.alibaba.rsocket.metadata.AppMetadata) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

AppMetadata (com.alibaba.rsocket.metadata.AppMetadata)8 NotNull (org.jetbrains.annotations.NotNull)2 RSocketServiceInstance (com.alibaba.rsocket.discovery.RSocketServiceInstance)1 BearerTokenMetadata (com.alibaba.rsocket.metadata.BearerTokenMetadata)1 RSocketCompositeMetadata (com.alibaba.rsocket.metadata.RSocketCompositeMetadata)1 RSocketBrokerResponderHandler (com.alibaba.spring.boot.rsocket.broker.responder.RSocketBrokerResponderHandler)1 RSocketAppPrincipal (com.alibaba.spring.boot.rsocket.broker.security.RSocketAppPrincipal)1 ApplicationErrorException (io.rsocket.exceptions.ApplicationErrorException)1 RejectedSetupException (io.rsocket.exceptions.RejectedSetupException)1 Map (java.util.Map)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1