RPC实战与核心原理
作者:互联网
download:《极客时间》RPC实战与核心原理
测试
- 定义服务接口
package com.wgs.rpc.test;public interface HelloService {String hello(String name);}
- 接口的真正实现,这是在服务端的实现,是隐藏的,不对外开放。
package com.wgs.rpc.test;public class HelloServiceImpl implements HelloService {@Overridepublic String hello(String name) {return "name : " + name;}}
- 服务端暴露服务:
package com.wgs.rpc.test;import com.wgs.rpc.framework.RPCFramework;public class RPCProvider {public static void main(String[] args) throws Exception {HelloService service = new HelloServiceImpl();RPCFramework.export(service, 8989);}}
- 客户端引用服务:
package com.wgs.rpc.test;import com.wgs.rpc.framework.RPCFramework;public class RPCProvider {public static void main(String[] args) throws Exception {HelloService service = new HelloServiceImpl();RPCFramework.export(service, 8989);}}
最后先运行服务端再运行客户端,即可打印出”name : Hello First RPC!”.
标签:实战,String,rpc,RPC,wgs,原理,com,public,name 来源: https://blog.51cto.com/15124238/2668930