项目作者: neilzhang

项目描述 :
simple java rpc framework
高级语言: Java
项目地址: git://github.com/neilzhang/simple-rpc.git
创建时间: 2017-12-27T02:55:29Z
项目社区:https://github.com/neilzhang/simple-rpc

开源协议:MIT License

下载


simple-rpc

一个简单的 Rpc 框架。

服务端代码样例:

  1. RpcServer rpcServer = RpcServer.builder()
  2. .port(8998)
  3. .zoo("127.0.0.1:2181")
  4. .bossThread(1)
  5. .workThread(4)
  6. .addListener(new MethodInvocationListener() {
  7. @Override
  8. public Object around(MethodInvocationPoint point) throws Throwable {
  9. // to do something as framework level without any business.
  10. // to add monitor.
  11. return point.proceed();
  12. }
  13. })
  14. .build();
  15. rpcServer.start(); //启动服务
  16. rpcServer.publish(HelloWordService.class, new HelloWordServiceImpl()); //注册服务

关闭服务

  1. rpcServer.shutdown();

客户端代码样例:

  1. RpcClient rpcClient = RpcClient.builder()
  2. .zkCoon("127.0.0.1:2181")
  3. .timeout(3000)
  4. .addListener(new MethodInvocationListener() {
  5. @Override
  6. public Object around(MethodInvocationPoint point) throws Throwable {
  7. // to do something as framework level without any business.
  8. // to add monitor.
  9. return point.proceed();
  10. }
  11. })
  12. .build();
  13. rpcClient.init();
  14. HelloWordService helloWordService = rpcClient.proxy(HelloWordService.class); //代理服务
  15. helloWordService.sayHello(); //调用远程服务

关闭客户端

  1. rpcClient.close();