<dependencies> <!-- Tajo Rpc --> <dependency> <groupId>org.apache.tajo</groupId> <artifactId>tajo-rpc</artifactId> <version>0.11.1</version> </dependency> </dependencies> public interface HelloService { String sayHello(String name); } public class HelloServiceImpl implements HelloService { @Override public String sayHello(String name) { return "Hello, " + name + "!"; } } public class RpcServerExample { public static void main(String[] args) throws IOException { RpcServer rpcServer = new RpcServer(new InetSocketAddress(port)); rpcServer.registerService(HelloService.class, new HelloServiceImpl()); rpcServer.start(); } } public class RpcClientExample { public static void main(String[] args) throws IOException, ServiceException { RpcClient rpcClient = new RpcClient(new InetSocketAddress(hostname, port)); HelloService helloService = rpcClient.getStub(HelloService.class); String response = helloService.sayHello("World"); rpcClient.close(); } }


上一篇:
下一篇:
切换中文