1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        snrpc簡(jiǎn)單 Netty RPC 框架

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

        snrpc 是一個(gè)簡(jiǎn)單的 Netty RPC 框架,使用 protostuff 1.07 作為序列化工具,使用 Netty-3.2.1 作為 NIO。

        使用方式:

        比如:

        1. server class;

        interface and implementor
                // define an interface:
                 public interface SnRpcInterface {
                    public String getMessage(String param);
                }
            // implement interface
            public class SnRpcImpl implements SnRpcInterface {
                public String getMessage(String param) {
                    return "hi,it is message from server...param+" + param;
                }
            }

        2, start server

            SnRpcInterface inter = new SnRpcImpl();
            SnRpcServer server = new SnNettyRpcServer(new Object[] { inter });
            try {
                server.start();
            } catch (Throwable e) {
                e.printStackTrace();
            }

        3,config file

        snrpcserver.properties

        #tcpNoDelay 
        snrpc.tcp.nodelay=true
        #call the bind method as many times as you want
        snrpc.tcp.reuseAddress=true
        #ISDEBUG
        snrpc.dev=true
        #TCP timeout
        snrpc.read.timeout=25000
        #server port
        snrpc.http.port=8080

        config.xml

        <?xml version="1.0" encoding="UTF-8"?><application>
         <!-- rpc interface services -->    
         <rpcServices>
                <rpcService name="SnRpcInterface" interface="org.stefan.snrpc.server.SnRpcInterface" overload="true">
                   <rpcImplementor  class="org.stefan.snrpc.server.SnRpcImpl"/> 
                </rpcService>
            </rpcServices></application>

        4, client invoker

            SnRpcConnectionFactory factory = new SnNettyRpcConnectionFactory(
                        "localhost", 8080);
            factory = new PoolableRpcConnectionFactory(factory);
            SnRpcClient client = new CommonSnRpcClient(factory);
            try {
                SnRpcInterface clazz = client.proxy(SnRpcInterface.class);
                String message = clazz.getMessage("come on");
                System.out.println("client receive message .... : " + message);
            } catch (Throwable e) {
                e.printStackTrace();
            }

        要求

        • JDK6+

        • Maven 2

        依賴

        • reflectasm-1.07.jar

        • asm-4.0.jar

        • log4j-1.2.16.jar

        • dom4j-1.6.1.jar

        • xml-apis-1.0.b2.jar

        • slf4j-api-1.6.6.jar

        • netty-3.2.1.Final.jar

        • jaxen-1.1.6.jar

        • protostuff-core-1.0.7.jar

        • protostuff-api-1.0.7.jar

        • protostuff-runtime-1.0.7.jar

        • protostuff-collectionschema-1.0.7.jar

        • commons-pool-1.6.jar

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

        手機(jī)掃一掃分享

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

        手機(jī)掃一掃分享

        編輯 分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            天天干天天日天天操天天爽天天射天天 | 啪啪网站网址 | 欧美国产精品一二三 | 台湾无码在线播放 | 国产aⅴ激情无码久久久无码 | 国产在线观看麻豆 | 天天色综合av | 欧美草屄| 骚逼熟女 | 亚洲无码成人影院 |