Java源码示例:com.alipay.sofa.rpc.config.ProviderConfig

示例1
private List<NewService> buildNewServices(ProviderConfig<?> config) {
    List<ServerConfig> servers = config.getServer();
    if (CommonUtils.isEmpty(servers)) {
        return Collections.emptyList();
    }
    return servers.stream().map(server -> {
        NewService service = new NewService();
        service.setId(buildServiceId(config, server));
        service.setName(buildServiceName(config));

        String host = getServerHost(server);
        int port = server.getPort();
        service.setAddress(host);
        service.setPort(port);

        Map<String, String> metaData = RegistryUtils.convertProviderToMap(config, server).entrySet().stream()
                .filter(e -> ConsulUtils.isValidMetaKey(e.getKey()))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        service.setMeta(metaData);
        service.setTags(Collections.singletonList(buildUniqueName(config, server.getProtocol())));

        service.setCheck(buildCheck(host, port));
        return service;
    }).collect(Collectors.toList());
}
 
示例2
@Test
public void testNeedToLoadProvider() {
    SentinelSofaRpcProviderFilter providerFilter = new SentinelSofaRpcProviderFilter();
    ProviderConfig providerConfig = new ProviderConfig();
    providerConfig.setInterfaceId(Serializer.class.getName());
    providerConfig.setId("AAA");
    FilterInvoker invoker = new FilterInvoker(null, null, providerConfig);
    assertTrue(providerFilter.needToLoad(invoker));

    providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false");
    assertFalse(providerFilter.needToLoad(invoker));

    providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "");
    assertTrue(providerFilter.needToLoad(invoker));

    RpcConfigs.putValue(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false");
    assertFalse(providerFilter.needToLoad(invoker));
}
 
示例3
@Override
public void onApplicationEvent(SofaBootRpcStartEvent event) {
    //choose disable metrics lookout
    disableLookout();

    //start fault tolerance
    faultToleranceConfigurator.startFaultTolerance();

    Collection<ProviderConfig> allProviderConfig = providerConfigContainer.getAllProviderConfig();
    if (!CollectionUtils.isEmpty(allProviderConfig)) {
        //start server
        serverConfigContainer.startServers();
    }

    //set allow all publish
    providerConfigContainer.setAllowPublish(true);

    //register registry
    providerConfigContainer.publishAllProviderConfig();

    //export dubbo
    providerConfigContainer.exportAllDubboProvideConfig();
}
 
示例4
/**
 * post unout binding
 *
 * @param contract           binding contract
 * @param binding            binding object
 * @param target             binding target
 * @param sofaRuntimeContext sofa runtime context
 */
@Override
public void postUnoutBinding(Object contract, RpcBinding binding, Object target,
                             SofaRuntimeContext sofaRuntimeContext) {
    ProviderConfig metadata = SpringBridge.getProviderConfigHelper().getProviderConfig((Contract) contract,
        binding, target);
    try {
        String key = SpringBridge.getProviderConfigContainer().createUniqueName((Contract) contract, binding);
        List<ServerConfig> servers = SpringBridge.getProviderConfigContainer().getProviderConfig(key).getServer();
        for (ServerConfig server : servers) {
            server.getServer().unRegisterProcessor(metadata, false);
        }
        SpringBridge.getProviderConfigContainer().removeProviderConfig(key);
    } catch (Exception e) {
        throw new ServiceRuntimeException(
            LogCodes.getLog(LogCodes.ERROR_PROXY_POST_UNPUBLISH_FAIL), e);
    }
}
 
示例5
@BeforeClass
public static void before() {
    ServerConfig serverConfig = new ServerConfig()
        .setStopTimeout(60000)
        .setPort(8803)
        .setProtocol(RpcConstants.PROTOCOL_TYPE_REST);

    ProviderConfig<RestService> providerConfig = new ProviderConfig<RestService>()
        .setInterfaceId(RestService.class.getName())
        .setRef(new RestServiceImpl())
        .setServer(serverConfig)
        .setBootstrap("rest")
        .setRegister(false);
    providerConfig.export();

    ConsumerConfig<RestService> consumerConfig = new ConsumerConfig<RestService>()
        .setInterfaceId(RestService.class.getName())
        .setDirectUrl("rest://127.0.0.1:8803")
        .setProtocol("rest")
        .setBootstrap("rest")
        .setTimeout(30000)
        .setRegister(false);
    restService = consumerConfig.refer();
}
 
示例6
/**
 * 转为服务端提供者对象
 *
 * @param config 服务提供者配置
 * @param server 服务端
 * @return 本地服务提供者对象
 */
public static ProviderInfo convertProviderToProviderInfo(ProviderConfig config, ServerConfig server) {
    ProviderInfo providerInfo = new ProviderInfo()
        .setPort(server.getPort())
        .setWeight(config.getWeight())
        .setSerializationType(config.getSerialization())
        .setProtocolType(server.getProtocol())
        .setPath(server.getContextPath())
        .setStaticAttrs(config.getParameters());
    String host = server.getHost();
    if (NetUtils.isLocalHost(host) || NetUtils.isAnyHost(host)) {
        host = SystemInfo.getLocalHost();
    }
    providerInfo.setHost(host);
    return providerInfo;
}
 
示例7
public static void main(String[] args) {

        ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("future-server");

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

        // C服务的服务端
        ProviderConfig<HelloService> CProvider = new ProviderConfig<HelloService>()
            .setApplication(applicationConfig)
            .setInterfaceId(HelloService.class.getName())
            .setRef(new HelloServiceImpl(1000))
            .setServer(serverConfig2);
        CProvider.export();
    }
 
示例8
public static void main(String[] args) {

        Filter customEchoFilter2 = new CustomEchoFilter2();

        ApplicationConfig application = new ApplicationConfig().setAppName("test-server");

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

        ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>()
            .setInterfaceId(HelloService.class.getName())
            .setApplication(application)
            .setRef(new HelloServiceImpl())
            .setServer(serverConfig)
            .setFilter(Arrays.asList("customEcho"))
            .setFilterRef(Arrays.asList(customEchoFilter2))
            .setRegister(false);

        providerConfig.export();

        LOGGER.error("started at pid {}", RpcRuntimeContext.PID);
    }
 
示例9
public static void main(String[] args) {

        // B服务里的C服务客户端
        ConsumerConfig<ServiceC> consumerConfig = new ConsumerConfig<ServiceC>()
            .setApplication(new ApplicationConfig().setAppName("BBB"))
            .setInterfaceId(ServiceC.class.getName())
            .setDirectUrl("bolt://127.0.0.1:12299?appName=CCC")
            .setRegister(false)
            .setInvokeType("callback") // 不设置,调用级别可设置
            .setTimeout(2000);

        ServiceC serviceC = consumerConfig.refer();

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

        ProviderConfig<ServiceB> providerConfig = new ProviderConfig<ServiceB>()
            .setInterfaceId(ServiceB.class.getName())
            .setApplication(new ApplicationConfig().setAppName("BBB"))
            .setRef(new ServiceBImpl(serviceC))
            .setServer(serverConfig)
            .setRegister(false);

        providerConfig.export();
    }
 
示例10
public static void main(String[] args) {
    ApplicationConfig application = new ApplicationConfig().setAppName("test-server");

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

    ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>()
        .setInterfaceId(HelloService.class.getName())
        .setApplication(application)
        .setRef(new HelloServiceImpl())
        .setServer(serverConfig)
        .setRegister(false);

    ProviderConfig<EchoService> providerConfig2 = new ProviderConfig<EchoService>()
        .setInterfaceId(EchoService.class.getName())
        .setApplication(application)
        .setRef(new EchoServiceImpl())
        .setServer(serverConfig)
        .setRegister(false);

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

    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
}
 
示例11
@Test
public void testCustomParams() {
    ProviderConfig providerConfig = new ProviderConfig();
    Map<String, String> map = new HashMap<String, String>();
    map.put("x", "y");
    map.put("a", "b");
    providerConfig.setParameters(map);

    ServerConfig server = new ServerConfig();
    providerConfig.setServer(server);
    List<String> urls = ZookeeperRegistryHelper.convertProviderToUrls(providerConfig);
    LOGGER.info(urls.toString());

    Assert.assertNotNull(urls);
    Assert.assertEquals(1, urls.size());

    String url = urls.get(0);

    ProviderInfo providerInfo = ProviderHelper.toProviderInfo(url);

    LOGGER.info(providerInfo.toString());

    Assert.assertEquals("b", providerInfo.getStaticAttr("a"));
    Assert.assertEquals("y", providerInfo.getStaticAttr("x"));

}
 
示例12
/**
 * 转为服务端提供者对象
 *
 * @param config 服务提供者配置
 * @param server 服务端
 * @return 本地服务提供者对象
 */
public static ProviderInfo convertProviderToProviderInfo(ProviderConfig config, ServerConfig server) {
    ProviderInfo providerInfo = new ProviderInfo()
        .setPort(server.getPort())
        .setWeight(config.getWeight())
        .setSerializationType(config.getSerialization())
        .setProtocolType(server.getProtocol())
        .setPath(server.getContextPath())
        .setStaticAttrs(config.getParameters());
    String host = server.getHost();
    if (NetUtils.isLocalHost(host) || NetUtils.isAnyHost(host)) {
        host = SystemInfo.getLocalHost();
    }
    providerInfo.setHost(host);
    return providerInfo;
}
 
示例13
private ProviderConfig<?> providerConfig(String uniqueId, int... ports) {
    ProviderConfig<?> provider = new ProviderConfig();
    provider.setInterfaceId(INTERFACE_ID)
            .setUniqueId(uniqueId)
            .setApplication(new ApplicationConfig().setAppName("consul-registry-test"))
            .setProxy("javassist")
            .setRegister(true)
            .setRegistry(registryConfig)
            .setSerialization("hessian2")
            .setWeight(222)
            .setTimeout(3000);

    IntStream.of(ports)
            .mapToObj(port ->
                    new ServerConfig()
                            .setProtocol("bolt")
                            .setHost("localhost")
                            .setPort(port)
            ).forEach(provider::setServer);
    return provider;
}
 
示例14
@BeforeClass
public static void startServer() {

    RpcRunningState.setUnitTestMode(true);
    // 只有2个线程 执行
    serverConfig = new ServerConfig()
        .setStopTimeout(0)
        .setPort(22222)
        .setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT)
        .setQueues(100).setCoreThreads(5).setMaxThreads(5);

    // 发布一个服务,每个请求要执行1秒
    ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>()
        .setInterfaceId(HelloService.class.getName())
        .setRef(new HelloServiceImpl())
        .setServer(serverConfig)
        .setRegister(false);
    providerConfig.export();
}
 
示例15
protected void recoverRegistryData() {

        for (ProviderConfig providerConfig : providerUrls.keySet()) {
            registerProviderUrls(providerConfig);
        }

        for (ConsumerConfig consumerConfig : consumerUrls.keySet()) {
            subscribeConsumerUrls(consumerConfig);
        }

    }
 
示例16
@Test
public void testNeedToLoadProviderAndConsumer() {
    SentinelSofaRpcProviderFilter providerFilter = new SentinelSofaRpcProviderFilter();
    ProviderConfig providerConfig = new ProviderConfig();
    providerConfig.setInterfaceId(Serializer.class.getName());
    providerConfig.setId("AAA");
    FilterInvoker providerInvoker = new FilterInvoker(null, null, providerConfig);
    assertTrue(providerFilter.needToLoad(providerInvoker));

    SentinelSofaRpcConsumerFilter consumerFilter = new SentinelSofaRpcConsumerFilter();
    ConsumerConfig consumerConfig = new ConsumerConfig();
    consumerConfig.setInterfaceId(Serializer.class.getName());
    consumerConfig.setId("BBB");
    FilterInvoker consumerInvoker = new FilterInvoker(null, null, consumerConfig);
    assertTrue(consumerFilter.needToLoad(consumerInvoker));

    providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false");
    assertFalse(providerFilter.needToLoad(providerInvoker));
    assertTrue(consumerFilter.needToLoad(consumerInvoker));

    providerConfig.setParameter(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "");
    assertTrue(providerFilter.needToLoad(providerInvoker));

    RpcConfigs.putValue(SentinelConstants.SOFA_RPC_SENTINEL_ENABLED, "false");
    assertFalse(providerFilter.needToLoad(providerInvoker));
    assertFalse(consumerFilter.needToLoad(consumerInvoker));
}
 
示例17
/**
 * pre out binding
 *
 * @param contract           binding contract
 * @param binding            binding object
 * @param target             binding target
 * @param sofaRuntimeContext sofa runtime context
 */
@Override
public void preOutBinding(Object contract, RpcBinding binding, Object target, SofaRuntimeContext sofaRuntimeContext) {
    String uniqueName = SpringBridge.getProviderConfigContainer().createUniqueName((Contract) contract, binding);
    ProviderConfig providerConfig = SpringBridge.getProviderConfigHelper().getProviderConfig((Contract) contract,
        binding, target);
    try {
        SpringBridge.getProviderConfigContainer().addProviderConfig(uniqueName, providerConfig);
    } catch (Exception e) {
        throw new ServiceRuntimeException(LogCodes.getLog(LogCodes.ERROR_PROXY_PUBLISH_FAIL), e);
    }
}
 
示例18
/**
 * 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;
}
 
示例19
@Test
public void includeListTest() {

    ProviderConfig providerConfig = new ProviderConfig();
    DefaultProviderBootstrap defaultProviderBootstra = new DefaultProviderBootstrap(providerConfig);
    boolean result = defaultProviderBootstra.inList("hello1", "hello2", "hello1");
    Assert.assertTrue(result);
}
 
示例20
/**
 * 发布所有 ProviderConfig 元数据信息到注册中心
 */
public void publishAllProviderConfig() {
    for (ProviderConfig providerConfig : getAllProviderConfig()) {

        ServerConfig serverConfig = (ServerConfig) providerConfig.getServer().get(0);
        if (!serverConfig.getProtocol().equalsIgnoreCase(SofaBootRpcConfigConstants.RPC_PROTOCOL_DUBBO)) {
            providerConfig.setRegister(true);

            List<RegistryConfig> registrys = providerConfig.getRegistry();
            for (RegistryConfig registryConfig : registrys) {

                Registry registry = RegistryFactory.getRegistry(registryConfig);
                registry.init();
                registry.start();

                registry.register(providerConfig);

                if (LOGGER.isInfoEnabled()) {
                    LOGGER.info("service published.  interfaceId[" + providerConfig.getInterfaceId() +
                        "]; protocol[" +
                        serverConfig.getProtocol() + "]");
                }
            }

        }
    }
}
 
示例21
private void covert(ProviderConfig<T> providerConfig, ServiceConfig<T> serviceConfig) {
    copyApplication(providerConfig, serviceConfig);
    DubboConvertor.copyRegistries(providerConfig, serviceConfig);
    copyServers(providerConfig, serviceConfig);
    copyProvider(providerConfig, serviceConfig);
    copyMethods(providerConfig, serviceConfig);
}
 
示例22
public static void main(String[] args) {

        String file = System.getProperty("user.home") + File.separator
            + "localFileTest" + File.separator + "localRegistry.reg";

        RegistryConfig registryConfig = new RegistryConfig().setProtocol("local")
            .setFile(file);

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

        ServerConfig serverConfig2 = new ServerConfig()
            .setPort(22200)
            .setProtocol(RpcConstants.PROTOCOL_TYPE_BOLT)
            .setDaemon(false);

        ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>()
            .setInterfaceId(HelloService.class.getName())
            .setRef(new HelloServiceImpl())
            .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);
    }
 
示例23
public static void main(String[] args) {
    /**
     * 运行时项目引入依赖
     <dependency>
         <groupId>com.alipay.sofa</groupId>
         <artifactId>registry-client-all</artifactId>
         <version>5.2.0</version>
     </dependency>
     */
    RegistryConfig registryConfig = new RegistryConfig()
        .setProtocol(RpcConstants.REGISTRY_PROTOCOL_SOFA)
        .setAddress("127.0.0.1:9603");

    ServerConfig serverConfig = new ServerConfig()
        .setProtocol("bolt")
        .setPort(12200)
        .setDaemon(false);

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

    providerConfig.export();
    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
}
 
示例24
public static void main(String[] args) {
    ServerConfig serverConfig = new ServerConfig()
        .setProtocol("bolt") // 设置一个协议,默认bolt
        .setPort(12200) // 设置一个端口,默认12200
        .setDaemon(false); // 非守护线程

    ProviderConfig<HelloService> providerConfig = new ProviderConfig<HelloService>()
        .setInterfaceId(HelloService.class.getName()) // 指定接口
        .setRef(new HelloServiceImpl()) // 指定实现
        .setServer(serverConfig); // 指定服务端

    providerConfig.export(); // 发布服务
}
 
示例25
public static void main(String[] args) {
    ServerConfig serverConfig = new ServerConfig()
        .setProtocol("bolt") // 设置一个协议,默认bolt
        .setPort(12200) // 设置一个端口,默认12200
        .setDaemon(false); // 非守护线程

    ProviderConfig<ProtoService> providerConfig = new ProviderConfig<ProtoService>()
        .setInterfaceId(ProtoService.class.getName()) // 指定接口
        .setRef(new ProtoServiceImpl()) // 指定实现
        .setServer(serverConfig); // 指定服务端

    providerConfig.export(); // 发布服务

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

    final AtomicInteger cnt = ((ProtoServiceImpl) providerConfig.getRef()).getCounter();
    final ThreadPoolExecutor executor = ((BoltServer) serverConfig.getServer()).getBizThreadPool();
    Thread thread = new Thread(new Runnable() {
        private long last = 0;

        @Override
        public void run() {
            while (true) {
                long count = cnt.get();
                long tps = count - last;
                LOGGER.error("last 1s invoke: {}, queue: {}", tps, executor.getQueue().size());
                last = count;

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                }
            }
        }
    }, "Print-tps-THREAD");
    thread.start();
}
 
示例26
protected void recoverRegistryData() {

        for (ProviderConfig providerConfig : providerUrls.keySet()) {
            registerProviderUrls(providerConfig);
        }

        for (ConsumerConfig consumerConfig : consumerUrls.keySet()) {
            subscribeConsumerUrls(consumerConfig);
        }

    }
 
示例27
@Test
public void testAll() {
    ServerConfig serverConfig = new ServerConfig()
        .setProtocol("bolt") // 设置一个协议,默认bolt
        .setPort(12200) // 设置一个端口,默认12200
        .setDaemon(false); // 非守护线程

    ProviderConfig<ProtobufService> providerConfig = new ProviderConfig<ProtobufService>()
        .setInterfaceId(ProtobufService.class.getName()) // 指定接口
        .setRef(new ProtobufServiceImpl()) // 指定实现
        .setServer(serverConfig); // 指定服务端
    providerConfig.export(); // 发布服务

    ConsumerConfig<ProtobufService> consumerConfig = new ConsumerConfig<ProtobufService>()
        .setInterfaceId(ProtobufService.class.getName()) // 指定接口
        .setProtocol("bolt") // 指定协议
        .setDirectUrl("bolt://127.0.0.1:12200") // 指定直连地址
        .setSerialization("protobuf") // 指定序列化协议,默认为hessian
        .setConnectTimeout(10 * 1000);
    ProtobufService helloService = consumerConfig.refer();

    EchoRequest request = EchoRequest.newBuilder().setName("sofa").setGroup(Group.A).build();
    EchoResponse response = helloService.echoObj(request);
    LOGGER.info(response.getCode() + ": " + response.getMessage());

    boolean error = false;
    try {
        helloService.echoObj(null);
    } catch (Exception e) {
        error = true;
    }
    Assert.assertTrue(error);

    Assert.assertEquals(200, response.getCode());
    Assert.assertEquals("protobuf works! sofa", response.getMessage());
}
 
示例28
@Override
public void batchUnRegister(List<ProviderConfig> configs) {
    for (ProviderConfig config : configs) {
        String appName = config.getAppName();
        try {
            unRegister(config);
        } catch (Exception e) {
            LOGGER.errorWithApp(appName, "Error when batch unregistry", e);
        }
    }
}
 
示例29
@Test
public void buildServiceName() {
    ServerConfig serverConfig = new ServerConfig()
        .setProtocol("bolt")
        .setHost("0.0.0.0")
        .setPort(12200);

    ProviderConfig<?> provider = new ProviderConfig();
    provider.setInterfaceId("com.alipay.xxx.TestService")
        .setApplication(new ApplicationConfig().setAppName("test-server"))
        .setUniqueId("nacos-test")
        .setProxy("javassist")
        .setRegister(true)
        .setSerialization("hessian2")
        .setServer(serverConfig)
        .setWeight(222)
        .setTimeout(3000);
    String serviceName = NacosRegistryHelper.buildServiceName(provider, RpcConstants.PROTOCOL_TYPE_BOLT);
    assertEquals(serviceName, "com.alipay.xxx.TestService:nacos-test:DEFAULT");

    serviceName = NacosRegistryHelper.buildServiceName(provider, RpcConstants.PROTOCOL_TYPE_TR);
    assertEquals(serviceName, "com.alipay.xxx.TestService:nacos-test:DEFAULT");

    serviceName = NacosRegistryHelper.buildServiceName(provider, RpcConstants.PROTOCOL_TYPE_TRIPLE);
    assertEquals(serviceName, "com.alipay.xxx.TestService:nacos-test:" + RpcConstants.PROTOCOL_TYPE_TRIPLE);

    serviceName = NacosRegistryHelper.buildServiceName(provider, RpcConstants.PROTOCOL_TYPE_REST);
    assertEquals(serviceName, "com.alipay.xxx.TestService:nacos-test:" + RpcConstants.PROTOCOL_TYPE_REST);
}
 
示例30
public static void main(String[] args) {

        ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("triple-server");

        int port = 50051;
        if (args.length != 0) {
            LOGGER.debug("first arg is {}", args[0]);
            port = Integer.valueOf(args[0]);
        }

        /*   RegistryConfig registryConfig = new RegistryConfig()
               .setProtocol("zookeeper")
               .setAddress("127.0.0.1:2181");*/

        ServerConfig serverConfig = new ServerConfig()
            .setProtocol(RpcConstants.PROTOCOL_TYPE_TRIPLE)
            .setPort(port);

        ProviderConfig<SofaGreeterTriple.IGreeter> providerConfig = new ProviderConfig<SofaGreeterTriple.IGreeter>()
            .setApplication(applicationConfig)
            .setBootstrap(RpcConstants.PROTOCOL_TYPE_TRIPLE)
            .setInterfaceId(SofaGreeterTriple.IGreeter.class.getName())
            .setRef(new TripleGreeterImpl())
            .setServer(serverConfig)
            .setRegister(false);
        // .setRegistry(registryConfig);

        providerConfig.export();

        synchronized (TripleServerRegistryApplication.class) {
            try {
                while (true) {
                    TripleServerRegistryApplication.class.wait();
                }
            } catch (InterruptedException e) {
                LOGGER.error("Exit by Interrupted");
            }
        }

    }