download: "Geek Time" RPC actual combat and core principles
test
- Define service interface
package com.wgs.rpc.test;public interface HelloService {String hello(String name);}
- The real realization of the interface, which is realized on the server side, is hidden and not open to the outside world.
package com.wgs.rpc.test;public class HelloServiceImpl implements HelloService {@Overridepublic String hello(String name) {return "name : " + name;}}
- Server-side exposed services:
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);}}
- Client referral service:
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);}}
Finally, run the server first and then the client, you can print out "name: Hello First RPC!".