Search in sources :

Example 1 with HelloService

use of com.alipay.sofa.rpc.quickstart.HelloService in project sofa-rpc by sofastack.

the class SofaRegistryClient method main.

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");
    ConsumerConfig<HelloService> consumerConfig = new ConsumerConfig<HelloService>().setInterfaceId(HelloService.class.getName()).setRegistry(registryConfig).setProtocol("bolt").setConnectTimeout(10 * 1000);
    HelloService helloService = consumerConfig.refer();
    LOGGER.warn("started at pid {}", RpcRuntimeContext.PID);
    try {
        while (true) {
            try {
                System.out.println(helloService.sayHello("world"));
            } catch (Exception e) {
                LOGGER.error(e.getMessage(), e);
            }
            try {
                Thread.sleep(2000);
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
        LOGGER.error("", e);
    }
}
Also used : RegistryConfig(com.alipay.sofa.rpc.config.RegistryConfig) HelloService(com.alipay.sofa.rpc.quickstart.HelloService) ConsumerConfig(com.alipay.sofa.rpc.config.ConsumerConfig)

Example 2 with HelloService

use of com.alipay.sofa.rpc.quickstart.HelloService in project sofa-rpc by sofastack.

the class SofaRegistryServer method main.

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);
}
Also used : RegistryConfig(com.alipay.sofa.rpc.config.RegistryConfig) ServerConfig(com.alipay.sofa.rpc.config.ServerConfig) ProviderConfig(com.alipay.sofa.rpc.config.ProviderConfig) HelloService(com.alipay.sofa.rpc.quickstart.HelloService) HelloServiceImpl(com.alipay.sofa.rpc.quickstart.HelloServiceImpl)

Aggregations

RegistryConfig (com.alipay.sofa.rpc.config.RegistryConfig)2 HelloService (com.alipay.sofa.rpc.quickstart.HelloService)2 ConsumerConfig (com.alipay.sofa.rpc.config.ConsumerConfig)1 ProviderConfig (com.alipay.sofa.rpc.config.ProviderConfig)1 ServerConfig (com.alipay.sofa.rpc.config.ServerConfig)1 HelloServiceImpl (com.alipay.sofa.rpc.quickstart.HelloServiceImpl)1