RPC actual combat and core principles

download: "Geek Time" RPC actual combat and core principles

test

  1. Define service interface
package com.wgs.rpc.test;public interface HelloService {String hello(String name);}
  1. 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;}}
  1. 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);}}
  1. 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!".


Guess you like

Origin blog.51cto.com/15124238/2668930