| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
SuzYSIS
7年前发布

RPC和服务注册框架实现

   <h2>simple-rpc</h2>    <p>RPC BASED ON NETTY Running in some business online.</p>    <h2>内部结构</h2>    <ul>     <li>IO netty</li>     <li>Serialize with protostuff, kryo</li>     <li>Transparent service discovery and connection management</li>    </ul>    <p style="text-align:center"><img src="http://static.open-open.com/lib/uploadImg/20170113/20170113223401_161.png"></p>    <h2>现有功能</h2>    <ul>     <li>基本的客户端、服务端交互</li>     <li>提供代理实现接口</li>     <li>spring 集成, xml配置和Java Config配置方式</li>     <li>服务发布订阅 DONE</li>     <li>断线重连 DONE</li>    </ul>    <h2>RoadMap</h2>    <ul>     <li>服务心跳检测</li>     <li>连接池</li>     <li>服务注册发布功能</li>     <li>服务管理、监控</li>     <li>服务调用日志链路跟踪</li>     <li>集成swagger功能,提供文档、测试、客户端生成</li>    </ul>    <h2>消息协议</h2>    <p>当前采用简单的在消息体前加上4byte的消息长度值</p>    <h2>使用示例</h2>    <p>// 需要先启动一个zookeeper作为服务注册发现中心</p>    <pre>  <code class="language-java">// 服务接口  public interface IHello {  `      String say(String hello);        int sum(int a, int b);      int sum(Integer a, Integer b);  }  // 服务实现  public class HelloImpl implements IHello {      public String say(String hello) {          return "return " + hello;      }        public int sum(int a, int b) {          return a + b;      }        public int sum(Integer a, Integer b) {          return a + b * 3;      }    }    // 客户端代码  // beanJavaConfig方式  @Bean      public CountService countService() {          RpcClientWithLB rpcClientWithLB = new RpcClientWithLB("fyes-counter");          rpcClientWithLB.setZkConn("127.0.0.1:2181");          rpcClientWithLB.init();          CountService countService = rpcClientWithLB.newProxy(CountService.class);          return countService;      }    // 服务端发布  // xml配置方式  <bean class="com.github.liuzhengyang.simplerpc.ServerFactoryBean" init-method="start">          <property name="serviceInterface" value="com.test.liuzhengyang.CountService"/>          <property name="port" value="8888"/>          <property name="serviceName" value="fyes-counter"/>          <property name="serviceImpl" ref="countServiceImpl"/>          <property name="zkConn" value="127.0.0.1:2181"/></code></pre>    <p> </p>    <p> </p>    <p> </p>    
 本文由用户 SuzYSIS 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1484318041170.html
RPC Java Java开发