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);
}
}
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);
}
Aggregations