Search in sources :

Example 1 with ProviderPubEvent

use of com.alipay.sofa.rpc.event.ProviderPubEvent in project sofa-rpc by sofastack.

the class ProviderPubTest method testPubLookout.

@Test
public void testPubLookout() {
    Registry registry = new DefaultRegistry();
    if (Lookout.registry() == NoopRegistry.INSTANCE) {
        Lookout.setRegistry(registry);
    }
    LookoutModule lookoutModule = new LookoutModule();
    Assert.assertEquals(true, lookoutModule.needLoad());
    lookoutModule.install();
    ProviderConfig providerConfig = new ProviderConfig();
    providerConfig.setInterfaceId("a");
    EventBus.post(new ProviderPubEvent(providerConfig));
    try {
        TimeUnit.SECONDS.sleep(5);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    RpcLookoutId rpcLookoutId = new RpcLookoutId();
    InfoWrapper result = Lookout.registry().get(rpcLookoutId.fetchProviderPubId());
    final Object value = result.value();
    Assert.assertTrue(value instanceof ProviderConfig);
    providerConfig = (ProviderConfig) value;
    Assert.assertEquals("a", providerConfig.getInterfaceId());
}
Also used : ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) DefaultRegistry(com.alipay.lookout.core.DefaultRegistry) RpcLookoutId(com.alipay.sofa.rpc.metrics.lookout.RpcLookoutId) NoopRegistry(com.alipay.lookout.api.NoopRegistry) Registry(com.alipay.lookout.api.Registry) DefaultRegistry(com.alipay.lookout.core.DefaultRegistry) ProviderPubEvent(com.alipay.sofa.rpc.event.ProviderPubEvent) InfoWrapper(com.alipay.lookout.core.InfoWrapper) Test(org.junit.Test)

Example 2 with ProviderPubEvent

use of com.alipay.sofa.rpc.event.ProviderPubEvent in project sofa-rpc by sofastack.

the class PolarisRegistry method register.

@Override
public void register(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    if (!config.isRegister()) {
        return;
    }
    try {
        List<InstanceRegisterRequest> services = buildPolarisRegister(config);
        if (CommonUtils.isNotEmpty(services)) {
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, config.getInterfaceId()));
            }
            for (InstanceRegisterRequest service : services) {
                registerPolarisService(config, service);
                if (LOGGER.isInfoEnabled(appName)) {
                    LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB, config.getInterfaceId()));
                }
            }
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, config.getInterfaceId()));
            }
        }
    } catch (SofaRpcRuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_REG_PROVIDER, "polarisRegistry", config.buildKey()), e);
    }
    if (EventBus.isEnable(ProviderPubEvent.class)) {
        ProviderPubEvent event = new ProviderPubEvent(config);
        EventBus.post(event);
    }
}
Also used : SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException) InstanceRegisterRequest(com.tencent.polaris.api.rpc.InstanceRegisterRequest) ProviderPubEvent(com.alipay.sofa.rpc.event.ProviderPubEvent) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException)

Example 3 with ProviderPubEvent

use of com.alipay.sofa.rpc.event.ProviderPubEvent in project sofa-rpc by sofastack.

the class LocalRegistry method register.

@Override
public void register(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    if (!config.isRegister()) {
        // 注册中心不注册或者服务不注册
        return;
    }
    List<ServerConfig> serverConfigs = config.getServer();
    if (CommonUtils.isNotEmpty(serverConfigs)) {
        for (ServerConfig server : serverConfigs) {
            String serviceName = LocalRegistryHelper.buildListDataId(config, server.getProtocol());
            ProviderInfo providerInfo = LocalRegistryHelper.convertProviderToProviderInfo(config, server);
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, serviceName));
            }
            doRegister(appName, serviceName, providerInfo);
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, serviceName));
            }
        }
        if (EventBus.isEnable(ProviderPubEvent.class)) {
            ProviderPubEvent event = new ProviderPubEvent(config);
            EventBus.post(event);
        }
    }
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) ProviderPubEvent(com.alipay.sofa.rpc.event.ProviderPubEvent)

Example 4 with ProviderPubEvent

use of com.alipay.sofa.rpc.event.ProviderPubEvent in project sofa-rpc by sofastack.

the class ConsulRegistry method register.

@Override
public void register(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        // 只订阅不注册
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    if (!config.isRegister()) {
        return;
    }
    // 注册服务端节点
    try {
        List<NewService> services = buildNewServices(config);
        if (CommonUtils.isNotEmpty(services)) {
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, config.getInterfaceId()));
            }
            for (NewService service : services) {
                registerConsulService(service);
                if (LOGGER.isInfoEnabled(appName)) {
                    LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB, config.getInterfaceId()));
                }
            }
            if (LOGGER.isInfoEnabled(appName)) {
                LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, config.getInterfaceId()));
            }
        }
    } catch (SofaRpcRuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_REG_PROVIDER, "consulRegistry", config.buildKey()), e);
    }
    if (EventBus.isEnable(ProviderPubEvent.class)) {
        ProviderPubEvent event = new ProviderPubEvent(config);
        EventBus.post(event);
    }
}
Also used : SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException) ProviderPubEvent(com.alipay.sofa.rpc.event.ProviderPubEvent) NewService(com.ecwid.consul.v1.agent.model.NewService) SofaRpcRuntimeException(com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException)

Example 5 with ProviderPubEvent

use of com.alipay.sofa.rpc.event.ProviderPubEvent in project sofa-rpc by sofastack.

the class MulticastRegistry method register.

@Override
public void register(ProviderConfig config) {
    String appName = config.getAppName();
    if (!registryConfig.isRegister()) {
        if (LOGGER.isInfoEnabled(appName)) {
            LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_REGISTRY_IGNORE));
        }
        return;
    }
    if (config.isRegister()) {
        List<ServerConfig> serverConfigs = config.getServer();
        if (CommonUtils.isNotEmpty(serverConfigs)) {
            for (ServerConfig server : serverConfigs) {
                String serviceName = MulticastRegistryHelper.buildListDataId(config, server.getProtocol());
                ProviderInfo providerInfo = MulticastRegistryHelper.convertProviderToProviderInfo(config, server);
                if (LOGGER.isInfoEnabled(appName)) {
                    LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_START, serviceName));
                }
                doRegister(appName, serviceName, providerInfo);
                if (LOGGER.isInfoEnabled(appName)) {
                    LOGGER.infoWithApp(appName, LogCodes.getLog(LogCodes.INFO_ROUTE_REGISTRY_PUB_OVER, serviceName));
                }
            }
            if (EventBus.isEnable(ProviderPubEvent.class)) {
                ProviderPubEvent event = new ProviderPubEvent(config);
                EventBus.post(event);
            }
        }
    }
}
Also used : ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ProviderInfo(com.alipay.sofa.rpc.client.ProviderInfo) ProviderPubEvent(com.alipay.sofa.rpc.event.ProviderPubEvent)

Aggregations

ProviderPubEvent (com.alipay.sofa.rpc.event.ProviderPubEvent)8 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)4 ProviderInfo (com.alipay.sofa.rpc.client.ProviderInfo)3 SofaRpcRuntimeException (com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException)3 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)2 Test (org.junit.Test)2 NoopRegistry (com.alipay.lookout.api.NoopRegistry)1 Registry (com.alipay.lookout.api.Registry)1 DefaultRegistry (com.alipay.lookout.core.DefaultRegistry)1 InfoWrapper (com.alipay.lookout.core.InfoWrapper)1 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)1 SofaRequest (com.alipay.sofa.rpc.core.request.SofaRequest)1 SofaResponse (com.alipay.sofa.rpc.core.response.SofaResponse)1 ClientEndInvokeEvent (com.alipay.sofa.rpc.event.ClientEndInvokeEvent)1 ConsumerSubEvent (com.alipay.sofa.rpc.event.ConsumerSubEvent)1 ServerSendEvent (com.alipay.sofa.rpc.event.ServerSendEvent)1 ServerStartedEvent (com.alipay.sofa.rpc.event.ServerStartedEvent)1 ServerStoppedEvent (com.alipay.sofa.rpc.event.ServerStoppedEvent)1 RpcLookoutId (com.alipay.sofa.rpc.metrics.lookout.RpcLookoutId)1 NewService (com.ecwid.consul.v1.agent.model.NewService)1