com.alipay.sofa.rpc.config.RegistryConfig Java Examples

The following examples show how to use com.alipay.sofa.rpc.config.RegistryConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultProviderBootstrap.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
/**
 * 反注册服务
 */
protected void unregister() {
    if (providerConfig.isRegister()) {
        List<RegistryConfig> registryConfigs = providerConfig.getRegistry();
        if (registryConfigs != null) {
            for (RegistryConfig registryConfig : registryConfigs) {
                Registry registry = RegistryFactory.getRegistry(registryConfig);
                try {
                    registry.unRegister(providerConfig);
                } catch (Exception e) {
                    String appName = providerConfig.getAppName();
                    if (LOGGER.isWarnEnabled(appName)) {
                        // TODO WARN
                        LOGGER.warnWithApp(appName, "Catch exception when unRegister from registry: " +
                            registryConfig.getId()
                            + ", but you can ignore if it's called by JVM shutdown hook", e);
                    }
                }
            }
        }
    }
}
 
Example #2
Source File: ZookeeperConfigurator.java    From sofa-rpc-boot-projects with Apache License 2.0 6 votes vote down vote up
@Override
public RegistryConfig buildFromAddress(String address) {
    String zkAddress = RegistryParseUtil.parseAddress(address,
        SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_ZOOKEEPER);
    Map<String, String> map = RegistryParseUtil.parseParam(address,
        SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_ZOOKEEPER);

    String file = map.get("file");

    if (StringUtils.isEmpty(file)) {
        file = SofaBootRpcConfigConstants.REGISTRY_FILE_PATH_DEFAULT;
    }

    return new RegistryConfig().setAddress(zkAddress).setFile(file)
        .setProtocol(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_ZOOKEEPER)
        .setParameters(map);
}
 
Example #3
Source File: ApplicationStartedListener.java    From sofa-dashboard with Apache License 2.0 6 votes vote down vote up
@Override
public void onApplicationEvent(ApplicationEvent event) {
    if (event instanceof ContextRefreshedEvent) {
        String address = environment.getProperty(SofaDashboardConstants.KEY);
        if (StringUtils.isNotBlank(address)) {
            RegistryConfig registryConfig = new RegistryConfig();
            if (address.startsWith(SofaDashboardConstants.ZOOKEEPER_PREFIX)) {
                RegistryConfigureProcessor processor = new ZookeeperConfigurator();
                registryConfig = processor.buildFromAddress(address);
            } else if (address.startsWith(SofaDashboardConstants.SOFA_PREFIX)) {
                registryConfig.setAddress(address.substring(SofaDashboardConstants.SOFA_PREFIX
                    .length()));
                registryConfig.setProtocol(SofaBootRpcConfigConstants.DEFAULT_REGISTRY);
                // config registry type
                Map<String, Object> props = new HashMap<>();
                props.put(SofaDashboardConstants.REGISTRY_TYPE,
                    SofaBootRpcConfigConstants.DEFAULT_REGISTRY);
                PropertySource propertySource = new MapPropertySource(
                    "customRegistryPropertySource", props);
                ((ConfigurableEnvironment) environment).getPropertySources().addLast(
                    propertySource);
            }
            registryDataSyncManager.start(registryConfig);
        }
    }
}
 
Example #4
Source File: MulticastRegistryTest.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Test
public void testSubAndUnsub() throws InterruptedException {
    RegistryConfig registryConfig = new RegistryConfig()
            .setProtocol("multicast")
            .setAddress("224.5.6.7:6667");
    MulticastRegistry server = new MulticastRegistry(registryConfig);
    server.init();
    MulticastRegistry client = new MulticastRegistry(registryConfig);
    client.init();


    server.register(PROVIDER_CONFIG);
    Thread.sleep(3000);

    ProviderGroup providerGroup = client.getAllProviderCache().get(MulticastRegistryHelper.buildListDataId(PROVIDER_CONFIG, SERVER_CONFIG.getProtocol()));
    Assert.assertFalse(providerGroup.isEmpty());

    server.unRegister(PROVIDER_CONFIG);

    Thread.sleep(3000);
    providerGroup = client.getAllProviderCache().get(MulticastRegistryHelper.buildListDataId(PROVIDER_CONFIG, SERVER_CONFIG.getProtocol()));
    Assert.assertTrue(providerGroup.isEmpty());


}
 
Example #5
Source File: MulticastRegistryTest.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Test
public void testSub() throws InterruptedException {
    RegistryConfig registryConfig = new RegistryConfig()
            .setProtocol("multicast")
            .setAddress("224.5.6.7:6668");
    MulticastRegistry server = new MulticastRegistry(registryConfig);
    server.init();
    server.register(PROVIDER_CONFIG);
    MulticastRegistry client = new MulticastRegistry(registryConfig);
    client.init();

    ProviderGroup providerGroup = client.getAllProviderCache().get(MulticastRegistryHelper.buildListDataId(PROVIDER_CONFIG, SERVER_CONFIG.getProtocol()));
    Assert.assertTrue(providerGroup == null);
    client.subscribe(CONSUMER_CONFIG);
    Thread.sleep(3000);
    ProviderGroup providerGroup1 = client.getAllProviderCache().get(MulticastRegistryHelper.buildListDataId(PROVIDER_CONFIG, SERVER_CONFIG.getProtocol()));
    Assert.assertFalse(providerGroup1.isEmpty());
}
 
Example #6
Source File: LocalRegistryTest.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() {
    FileUtils.cleanDirectory(new File(filePath));

    registryConfig = new RegistryConfig()
        .setProtocol("local")
        //.setParameter("registry.local.scan.period", "1000")
        .setSubscribe(true)
        .setRegister(true);
    //        registryConfig.setAddress()
    //                .setConnectTimeout(5000)
    //                .setHeartbeatPeriod(60000)
    //                .setReconnectPeriod(15000)
    //                .setBatch(true)
    //                .setBatchSize(10);

    registry = (LocalRegistry) RegistryFactory.getRegistry(registryConfig);
    try {
        registry.init();
    } catch (Exception e) {
        Assert.assertTrue(e instanceof SofaRpcRuntimeException);
    }
    registryConfig.setFile(file);
    registry.init();
    registry.start();
}
 
Example #7
Source File: LocalRegistryTest.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
public void notifyConsumerTest() {
    LocalRegistry registry = new LocalRegistry(new RegistryConfig());
    ConsumerConfig<?> consumer = new ConsumerConfig();
    consumer.setInterfaceId("test");
    LocalRegistryTest.MockProviderInfoListener providerInfoListener = new LocalRegistryTest.MockProviderInfoListener();
    consumer.setProviderInfoListener(providerInfoListener);
    registry.subscribe(consumer);
    String key = LocalRegistryHelper.buildListDataId(consumer, consumer.getProtocol());

    registry.memoryCache.put(key, new ProviderGroup());

    Map<String, ProviderGroup> newCache = new HashMap<String, ProviderGroup>();
    ProviderGroup newProviderGroup = new ProviderGroup();
    ProviderInfo providerInfo = new ProviderInfo().setHost("0.0.0.0");
    newProviderGroup.add(providerInfo);
    newCache.put(key, newProviderGroup);

    registry.notifyConsumer(newCache);

    Map<String, ProviderGroup> ps = providerInfoListener.getData();
    Assert.assertTrue(ps.size() > 0);
    Assert.assertNotNull(ps.get(RpcConstants.ADDRESS_DEFAULT_GROUP));
    Assert.assertTrue(ps.get(RpcConstants.ADDRESS_DEFAULT_GROUP).size() == 1);
}
 
Example #8
Source File: NacosRegistryNamespaceTest.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithNamespace() {
    RegistryConfig registryConfig = new RegistryConfig()
        .setProtocol("nacos")
        .setSubscribe(true)
        .setAddress("127.0.0.1:8848/namespace")
        .setRegister(true);

    NacosRegistry registry = (NacosRegistry) RegistryFactory.getRegistry(registryConfig);
    registry.init();

    Properties properties = registry.getNacosConfig();

    String address = properties.getProperty(PropertyKeyConst.SERVER_ADDR);

    Assert.assertEquals("127.0.0.1:8848", address);
    String namespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
    Assert.assertEquals("namespace", namespace);

}
 
Example #9
Source File: NacosRegistryNamespaceTest.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithoutNamespace() {
    RegistryConfig registryConfig = new RegistryConfig()
        .setProtocol("nacos")
        .setSubscribe(true)
        .setAddress("127.0.0.1:8848/")
        .setRegister(true);

    NacosRegistry registry = (NacosRegistry) RegistryFactory.getRegistry(registryConfig);
    registry.init();

    Properties properties = registry.getNacosConfig();

    String address = properties.getProperty(PropertyKeyConst.SERVER_ADDR);

    Assert.assertEquals("127.0.0.1:8848", address);
    String namespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
    Assert.assertEquals("sofa-rpc", namespace);

}
 
Example #10
Source File: NacosRegistryNamespaceTest.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithoutSlashNamespace() {
    RegistryConfig registryConfig = new RegistryConfig()
        .setProtocol("nacos")
        .setSubscribe(true)
        .setAddress("127.0.0.1:8848")
        .setRegister(true);

    NacosRegistry registry = (NacosRegistry) RegistryFactory.getRegistry(registryConfig);
    registry.init();

    Properties properties = registry.getNacosConfig();

    String address = properties.getProperty(PropertyKeyConst.SERVER_ADDR);

    Assert.assertEquals("127.0.0.1:8848", address);
    String namespace = properties.getProperty(PropertyKeyConst.NAMESPACE);
    //default namespace
    Assert.assertEquals("sofa-rpc", namespace);

}
 
Example #11
Source File: MeshRouter.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Override
public boolean needToLoad(ConsumerBootstrap consumerBootstrap) {
    ConsumerConfig consumerConfig = consumerBootstrap.getConsumerConfig();
    // 不是直连,且从注册中心订阅配置
    final boolean isDirect = StringUtils.isNotBlank(consumerConfig.getDirectUrl());
    final List<RegistryConfig> registrys = consumerConfig.getRegistry();
    boolean isMesh = false;

    if (registrys != null) {
        for (RegistryConfig registry : registrys) {
            if (registry.getProtocol().equalsIgnoreCase(RpcConstants.REGISTRY_PROTOCOL_MESH)) {
                isMesh = true;
                break;
            }
        }
    }
    return !isDirect && isMesh;
}
 
Example #12
Source File: DefaultConsumerBootstrap.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
@Override
public List<ProviderGroup> subscribe() {
    List<ProviderGroup> result = null;
    String directUrl = consumerConfig.getDirectUrl();
    if (StringUtils.isNotEmpty(directUrl)) {
        // 如果走直连
        result = subscribeFromDirectUrl(directUrl);
    } else {
        // 没有配置url直连
        List<RegistryConfig> registryConfigs = consumerConfig.getRegistry();
        if (CommonUtils.isNotEmpty(registryConfigs)) {
            // 从多个注册中心订阅服务列表
            result = subscribeFromRegistries();
        }
    }
    return result;
}
 
Example #13
Source File: DefaultConsumerBootstrap.java    From sofa-rpc with Apache License 2.0 6 votes vote down vote up
/**
 * 取消订阅服务列表
 */
public void unSubscribe() {
    if (StringUtils.isEmpty(consumerConfig.getDirectUrl()) && consumerConfig.isSubscribe()) {
        List<RegistryConfig> registryConfigs = consumerConfig.getRegistry();
        if (registryConfigs != null) {
            for (RegistryConfig registryConfig : registryConfigs) {
                Registry registry = RegistryFactory.getRegistry(registryConfig);
                try {
                    registry.unSubscribe(consumerConfig);
                } catch (Exception e) {
                    String appName = consumerConfig.getAppName();
                    if (LOGGER.isWarnEnabled(appName)) {
                        LOGGER.warnWithApp(appName,
                            "Catch exception when unSubscribe from registry: " + registryConfig.getId()
                                + ", but you can ignore if it's called by JVM shutdown hook", e);
                    }
                }
            }
        }
    }
}
 
Example #14
Source File: ZookeeperRegistryDestroyTest.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() {
    registryConfig = new RegistryConfig()
        .setProtocol(RpcConstants.REGISTRY_PROTOCOL_ZK)
        .setSubscribe(true)
        .setAddress("127.0.0.1:2181")
        .setRegister(true);

    registry = (ZookeeperRegistry) RegistryFactory.getRegistry(registryConfig);
    registry.init();
    Assert.assertTrue(registry.start());
}
 
Example #15
Source File: MockTestRegistryTest.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Test
public void testAll() {

    RegistryConfig registryConfig = new RegistryConfig()
        .setProtocol("mocktest");

    ServerConfig serverConfig2 = new ServerConfig()
        .setPort(22222)
        .setDaemon(false);

    // 服务端
    ProviderConfig<HelloService> CProvider = new ProviderConfig<HelloService>()
        .setInterfaceId(HelloService.class.getName())
        .setRef(new HelloServiceImpl(1000))
        .setRegistry(registryConfig)
        .setServer(serverConfig2);
    CProvider.export();

    // 客户端
    ConsumerConfig<HelloService> BConsumer = new ConsumerConfig<HelloService>()
        .setInterfaceId(HelloService.class.getName())
        .setInvokeType(RpcConstants.INVOKER_TYPE_SYNC)
        .setTimeout(5000)
        .setRegistry(registryConfig);
    HelloService helloService = BConsumer.refer();

    // 正常
    boolean error = false;
    try {
        String ret = helloService.sayHello("xxx", 22);
        Assert.assertNotNull(ret);
    } catch (Exception e) {
        e.printStackTrace();
        error = true;
    }
    Assert.assertFalse(error);
}
 
Example #16
Source File: ZookeeperRegistryDataSync.java    From sofa-dashboard with Apache License 2.0 5 votes vote down vote up
@Override
public boolean start(RegistryConfig registryConfig) {

    LOGGER.info("start zookeeper registry data sync,config is {}", registryConfig.getAddress());
    zookeeperAdminRegistry.start(registryConfig);
    zookeeperAdminRegistry.subscribe(SofaDashboardConstants.DEFAULT_GROUP,
            (type, data) -> LOGGER.info("data add,data is {}", data));
    return true;
}
 
Example #17
Source File: RegistryDataSyncManagerImpl.java    From sofa-dashboard with Apache License 2.0 5 votes vote down vote up
@Override
public boolean start(RegistryConfig registryConfig) {

    RegistryDataSync registryDataSync = syncManager.get(registryConfig.getProtocol());

    if (registryDataSync != null) {
        registryDataSync.start(registryConfig);
        return true;
    } else {
        LOGGER.error("registryConfig is {}, not exist in our support list", registryConfig);
        return false;
    }
}
 
Example #18
Source File: SofaRegistryRestClient.java    From sofa-dashboard with Apache License 2.0 5 votes vote down vote up
public void init(RegistryConfig registryConfig) {
    String endPointAddress = registryConfig.getAddress();
    if (!endPointAddress.contains(SofaDashboardConstants.COLON)) {
        throw new RuntimeException(
            "Please check your session address.Illegal session address is [" + endPointAddress
                    + "]");
    }
    sessionAddress = endPointAddress.split(SofaDashboardConstants.COLON)[0];
    port = Integer.valueOf(endPointAddress.split(SofaDashboardConstants.COLON)[1]);
}
 
Example #19
Source File: DubboConvertor.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
public static void copyRegistryFields(com.alipay.sofa.rpc.config.RegistryConfig sofaRegistryConfig,
                                      com.alibaba.dubbo.config.RegistryConfig dubboRegistryConfig) {
    dubboRegistryConfig.setAddress(sofaRegistryConfig.getAddress());
    dubboRegistryConfig.setProtocol(sofaRegistryConfig.getProtocol());
    dubboRegistryConfig.setRegister(sofaRegistryConfig.isRegister());
    dubboRegistryConfig.setSubscribe(sofaRegistryConfig.isSubscribe());
    dubboRegistryConfig.setAddress(sofaRegistryConfig.getAddress());
    dubboRegistryConfig.setTimeout(sofaRegistryConfig.getTimeout());
    dubboRegistryConfig.setId(sofaRegistryConfig.getId());
    dubboRegistryConfig.setParameters(sofaRegistryConfig.getParameters());
}
 
Example #20
Source File: RegistryFactory.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
/**
 * 关闭全部注册中心
 */
public static void destroyAll() {
    for (Map.Entry<RegistryConfig, Registry> entry : ALL_REGISTRIES.entrySet()) {
        RegistryConfig config = entry.getKey();
        Registry registry = entry.getValue();
        try {
            registry.destroy();
            ALL_REGISTRIES.remove(config);
        } catch (Exception e) {
            LOGGER.error(LogCodes.getLog(LogCodes.ERROR_DESTRORY_REGISTRY, config), e);
        }
    }
}
 
Example #21
Source File: SofaRegistryDataSync.java    From sofa-dashboard with Apache License 2.0 5 votes vote down vote up
@Override
public boolean start(RegistryConfig registryConfig) {

    LOGGER.info("start sofa registry data sync,config is {}", registryConfig.getAddress());
    sofaAdminRegistry.start(registryConfig);
    return true;
}
 
Example #22
Source File: NacosRegistryTest.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
/**
 * Sets up.
 */
@Before
public void setUp() {
    registryConfig = new RegistryConfig()
        .setProtocol("nacos")
        .setSubscribe(true)
        .setAddress("127.0.0.1:" + nacosProcess.getServerPort())
        .setRegister(true);

    registry = (NacosRegistry) RegistryFactory.getRegistry(registryConfig);
    registry.init();
    Assert.assertTrue(registry.start());
}
 
Example #23
Source File: SofaRegistryTest.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {

    registryConfig = new RegistryConfig()
        .setProtocol("sofa")
        .setSubscribe(true)
        .setRegister(true)
        .setAddress("127.0.0.1:9603");

    registry = (SofaRegistry) RegistryFactory.getRegistry(registryConfig);
    registry.init();
    Assert.assertTrue(registry.start());
}
 
Example #24
Source File: SofaRegistryClient.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
public static synchronized RegistryClient getRegistryClient(String appName, RegistryConfig registryConfig) {
    if (registryClient == null) {
        String address = registryConfig.getAddress();
        final String portStr = StringUtils.substringAfter(address, ":");
        RegistryClientConfig config = DefaultRegistryClientConfigBuilder.start()
            .setAppName(appName).setDataCenter(LOCAL_DATACENTER).setZone(LOCAL_REGION)
            .setRegistryEndpoint(StringUtils.substringBefore(address, ":"))
            .setRegistryEndpointPort(Integer.parseInt(portStr)).build();

        registryClient = new DefaultRegistryClient(config);
        ((DefaultRegistryClient) registryClient).init();
    }
    return registryClient;
}
 
Example #25
Source File: SofaAdminRegistry.java    From sofa-dashboard with Apache License 2.0 5 votes vote down vote up
@Override
public boolean start(RegistryConfig registryConfig) {
    try {
        restTemplateClient.init(registryConfig);
        CheckSumTask checkSumTask = new CheckSumTask();
        // 60s
        executor.scheduleWithFixedDelay(checkSumTask, 0, 60, TimeUnit.SECONDS);
    } catch (Throwable t) {
        LOGGER.error("Failed to start sofa registry.", t);
    }
    return true;
}
 
Example #26
Source File: ConsulRegistryTest.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    consul = ConsulStarterBuilder.consulStarter()
        .withConsulVersion("1.4.0")
        .build()
        .start();

    registryConfig = new RegistryConfig()
        .setProtocol("consul")
        .setAddress("127.0.0.1:" + consul.getHttpPort())
        .setRegister(true);

    registry = (ConsulRegistry) RegistryFactory.getRegistry(registryConfig);
    registry.init();
}
 
Example #27
Source File: RpcBindingAdapter.java    From sofa-rpc-boot-projects with Apache License 2.0 5 votes vote down vote up
/**
 * out binding, out binding means provide service
 *
 * @param contract           binding contract
 * @param binding            binding object
 * @param target             binding target
 * @param sofaRuntimeContext sofa runtime context
 * @return binding result
 */
@Override
public Object outBinding(Object contract, RpcBinding binding, Object target, SofaRuntimeContext sofaRuntimeContext) {

    String uniqueName = SpringBridge.getProviderConfigContainer().createUniqueName((Contract) contract, binding);
    ProviderConfig providerConfig = SpringBridge.getProviderConfigContainer().getProviderConfig(uniqueName);

    if (providerConfig == null) {
        throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.INFO_SERVICE_METADATA_IS_NULL, uniqueName));
    }

    try {
        providerConfig.export();
    } catch (Exception e) {
        throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.ERROR_PROXY_PUBLISH_FAIL), e);
    }

    if (SpringBridge.getProviderConfigContainer().isAllowPublish()) {
        providerConfig.setRegister(true);
        List<RegistryConfig> registrys = providerConfig.getRegistry();
        for (RegistryConfig registryConfig : registrys) {
            Registry registry = RegistryFactory.getRegistry(registryConfig);
            registry.init();
            registry.start();
            registry.register(providerConfig);
        }
    }
    return Boolean.TRUE;
}
 
Example #28
Source File: MulticastRegistryTest.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Test
public void testInit() throws NoSuchFieldException, IllegalAccessException {
    RegistryConfig registryConfig = new RegistryConfig()
        .setProtocol("multicast")
        .setAddress("224.5.6.7:6666");
    MulticastRegistry multicastRegistry = new MulticastRegistry(registryConfig);
    multicastRegistry.init();

    Assert.assertEquals("224.5.6.7", getAddress(multicastRegistry));
    Assert.assertEquals(6666, getPort(multicastRegistry));
}
 
Example #29
Source File: NacosConfigurator.java    From sofa-rpc-boot-projects with Apache License 2.0 5 votes vote down vote up
@Override
public RegistryConfig buildFromAddress(String address) {
    String nacosAddress = RegistryParseUtil.parseAddress(address,
        SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_NACOS);
    Map<String, String> map = RegistryParseUtil.parseParam(address,
        SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_NACOS);

    return new RegistryConfig().setAddress(nacosAddress).setParameters(map)
        .setProtocol(SofaBootRpcConfigConstants.REGISTRY_PROTOCOL_NACOS);
}
 
Example #30
Source File: ZookeeperBoltServerMain.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        /**
         * 运行需要pom.xml里增加依赖 
         <dependency>
             <groupId>org.apache.curator</groupId>
             <artifactId>curator-recipes</artifactId>
             <scope>test</scope>
         </dependency>
         */
        RegistryConfig registryConfig = new RegistryConfig()
            .setProtocol(RpcConstants.REGISTRY_PROTOCOL_ZK)
            .setAddress("127.0.0.1:2181");

        ServerConfig serverConfig = new ServerConfig()
            .setPort(22101)
            .setDaemon(false);

        ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>()
            .setInterfaceId(HelloService.class.getName())
            .setRef(new HelloServiceImpl("result from 22101"))
            .setServer(serverConfig)
            .setRegistry(registryConfig);

        ProviderConfig<EchoService> providerConfig2 = new ProviderConfig<EchoService>()
            .setInterfaceId(EchoService.class.getName())
            .setRef(new EchoServiceImpl())
            .setServer(serverConfig)
            .setRegistry(registryConfig);

        providerConfig.export();
        providerConfig2.export();

        LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
    }