<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          HRPC輕量級(jí)高性能 RPC 框架

          聯(lián)合創(chuàng)作 · 2023-09-23 12:47

          HRPC

           HRPC是一款基于NettyZookeeper設(shè)計(jì)的輕量級(jí)高性能RPC框架。

          特性

          • 采用Protostuff序列化;

          • 高性能,負(fù)載均衡;

          • 支持服務(wù)的注冊(cè)和訂閱;

          • 支持同步及異步2種調(diào)用方式;

          • 長(zhǎng)連接,自動(dòng)重連;

          • 采用cglib動(dòng)態(tài)代理;

          • 代碼簡(jiǎn)答,易上手;

          • 支持Spring;

          HRPC結(jié)構(gòu)圖

          服務(wù)注冊(cè)中心

          服務(wù)端

          1. 通過Spring配置

          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:context="http://www.springframework.org/schema/context"
                 xsi:schemaLocation="http://www.springframework.org/schema/context
                 http://www.springframework.org/schema/context/spring-context.xsd">
              <!--掃描需求發(fā)布的服務(wù)所在的包-->
              <context:component-scan base-package="com.yingjun.rpc.service.impl"/>
              <context:property-placeholder location="classpath:system.properties"/>
              <!--服務(wù)端配置-->
              <bean id="rpcServer" class="com.yingjun.rpc.server.RPCServer">
                  <constructor-arg name="zookeeper" value="${zookeeper.address}"/>
                  <constructor-arg name="serverAddress" value="${server.address}"/>
              </bean>
          </beans>

          2. 服務(wù)接口

          public interface UserService {
              public User getUser(String phone);
              public User updateUser(User user);
          }

          3. 注冊(cè)服務(wù)實(shí)現(xiàn)

          @HRPCService(UserService.class)
          public class UserServiceImpl implements UserService {
              @Override
              public User getUser(String phone) {
                  User user =new User(111,"yingjun",phone);
                  return user;
              }
              @Override
              public User updateUser(User user) {
                  user.setName("yingjun@update");
                  return user;
              }
          }

          客戶端

          1. Spring配置

          <?xml version="1.0" encoding="UTF-8"?>
          <beans xmlns="http://www.springframework.org/schema/beans"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xmlns:context="http://www.springframework.org/schema/context"
                 xsi:schemaLocation="http://www.springframework.org/schema/beans
                 http://www.springframework.org/schema/beans/spring-beans.xsd
                 http://www.springframework.org/schema/context
                 http://www.springframework.org/schema/context/spring-context.xsd">
              <context:annotation-config/>
              <context:property-placeholder location="classpath:system.properties"/>
              <!--客戶端配置-->
              <bean id="rpcClient" class="com.yingjun.rpc.client.RPCClient">
                  <constructor-arg name="zookeeper" value="${zookeeper.address}"/>
                  <!--訂閱需要用到的接口-->
                  <constructor-arg name="interfaces">
                      <list>
                          <value>com.yingjun.rpc.service.OrderService</value>
                          <value>com.yingjun.rpc.service.UserService</value>
                          <value>com.yingjun.rpc.service.GoodsService</value>
                      </list>
                  </constructor-arg>
              </bean>
          </beans>

          2. 同步調(diào)用

          UserService userService = rpcClient.createProxy(UserService.class);
          User user1 = userService.getUser("188888888");
          logger.info("result:" + user1.toString());

          3. 異步調(diào)用

          AsyncRPCProxy asyncProxy = rpcClient.createAsyncProxy(UserService.class);
          asyncProxy.call("getUser", new AsyncRPCCallback() {
               @Override
               public void success(Object result) {
                   logger.info("result:" + result.toString());
               }
               @Override
               public void fail(Exception e) {
                   logger.error("result:" + e.getMessage());
               }
           }, "188888888");

          為什么選擇Protostuff ?

          瀏覽 23
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  天天躁夜夜躁av 无码视频中文字幕 | 少妇厨房偷情理伦 | 大香蕉网在线视频 | 丁香六月激情 | 99re在线视频免费观看 |