远程服务协议-netty协议
来源:互联网 发布:uc监控软件 编辑:程序博客网 时间:2024/05/17 04:08
netty协议的配置文件为:org/frameworkset/spi/manager-rpc-netty.xml
被导入在rpc基础配置文件manager-rpc-service.xml中:
<managerimport file="org/frameworkset/spi/manager-rpc-netty.xml" />
下面具体介绍Netty配置:
1.1.1.1.1 Netty服务请求和响应处理类
<!--
netty服务请求和响应处理类
-->
<property name="rpc.netty.RPCServerIoHandler" singlable="true"
class="org.frameworkset.netty.NettyIOHandler">
<construction>
<property name="name" value="RPCServerIoHandler" class="String" />
<property name="request_handler" refid="attr:rpc.request_handler" />
</construction>
</property>
1.1.1.1.2 Netty服务器组件
<!--
netty服务器组件
-->
<property name="rpc.netty.server" singlable="true"
class="org.frameworkset.netty.NettyRPCServer">
<construction>
<property name="netty.params" refid="attr:rpc.protocol.netty.params" />
</construction>
</property>
1.1.1.1.3 Netty的链接参数配置
<!--
netty框架的链接参数
-->
<property name="rpc.protocol.netty.params">
<map>
<!-- 连接超时时间,默认值60秒,单位:秒 -->
<property name="connection.timeout" value="60" />
<!--
服务器绑定端口
-->
<property name="connection.bind.port" value="12346" />
<!--
服务器绑定ip
-->
<property name="connection.bind.ip" value="172.16.17.216" />
<!--
ssl配置参数开始
如果启用ssl,那么必须在rpc.protocol.netty.ssl.client和
rpc.protocol.netty.ssl.server中配置证书的相关信息
服务器端只需要配置rpc.protocol.netty.ssl.server
客服端只需要配置rpc.protocol.netty.ssl.client
-->
<property name="enablessl" value="false" />
<!-- <property name="enabledCipherSuites" value="SSL_DH_anon_WITH_RC4_128_MD5" >-->
<!-- <editor class="org.frameworkset.spi.assemble.StringArrayEditor"/>-->
<!-- </property>-->
<!-- 下述参数不要配置 -->
<!-- <property name="enabledProtocols" value="TLS" >-->
<!-- <editor class="org.frameworkset.spi.assemble.StringArrayEditor"/>-->
<!-- </property>-->
<property name="needClientAuth" value="true" />
<property name="wantClientAuth" value="true" />
<!-- ssl配置参数结束 -->
</map>
</property>
<!--
netty框架的ssl client参数
-->
<property name="rpc.protocol.netty.ssl.client">
<map>
<!-- 连接超时时间,默认值60秒,单位:秒 -->
<property name="keyStore" value="keystore/client.ks" />
<!--
服务器绑定端口
-->
<property name="keyStorePassword" value="123456" />
<!--
服务器绑定ip
-->
<property name="trustStore" value="keystore/client.ts" />
<property name="trustStorePassword" value="123456" />
</map>
</property>
<!--
netty框架的ssl server参数
-->
<property name="rpc.protocol.netty.ssl.server">
<map>
<!-- 连接超时时间,默认值60秒,单位:秒 -->
<property name="keyStore" value="keystore/server.ks" />
<!--
服务器绑定端口
-->
<property name="keyStorePassword" value="123456" />
<!--
服务器绑定ip
-->
<property name="trustStore" value="keystore/server.ts" />
<property name="trustStorePassword" value="123456" />
</map>
</property>
1.1.1.2 Netty协议使用方法
1.1.1.2.1 服务组件配置
客服端和服务器端配置组件:
<property name="rpc.test" singlable="true" class="org.frameworkset.spi.remote.RPCTest"/>
1.1.1.2.2 启动服务器
先在配置服务器上配置好以下参数:
<!--
服务器绑定端口
-->
<property name="connection.bind.port" value="12347" />
<!--
服务器绑定ip
-->
<property name="connection.bind.ip" value="172.16.17.216" />
在服务器端启动netty服务器协议,启动后客服端即可进行远程服务调用。启动netty服务器方法如下:
org.frameworkset.spi.remote.RPCHelper.getRPCHelper().startNettyServer();
1.1.1.2.3 获取远程组件实例
单点调用
RPCTestInf testInf = (RPCTestInf)BaseSPIManager.getBeanObject("(netty::172.16.17.216:1186)/rpc.test");
多点调用
RPCTestInf testInf = (RPCTestInf)BaseSPIManager.getBeanObject("(netty::192.168.11.102:1186;192.168.11.102:12346)/rpc.test");
组播调用
RPCTestInf testInf = (RPCTestInf)BaseSPIManager.getBeanObject("(netty::all)/rpc.test");
单点调用-传递认证信息
RPCTestInf testInf = (RPCTestInf)BaseSPIManager.getBeanObject("(netty::172.16.17.216:1186)/rpc.test?user=admin&password=123456");
多点调用-传递认证信息
RPCTestInf testInf = (RPCTestInf)BaseSPIManager.getBeanObject("(netty::192.168.11.102:1186;192.168.11.102:12346)/rpc.test?user=admin&password=123456");
组播调用-传递认证信息
RPCTestInf testInf = (RPCTestInf)BaseSPIManager.getBeanObject("(netty::all)/rpc.test?user=admin&password=123456");
1.1.1.2.4 远程方法调用
Object count = testInf.getCount();
1.1.1.2.5 调用结果处理
单点调用的结果就是服务接口返回的值,无需处理。如果方法调用失败,系统将抛出具体的远程异常。
多点调用和组播调用的结果处理方法一样,以多点调用为例:
RPCTestInf testInf = (RPCTestInf)BaseSPIManager.getBeanObject("(netty::192.168.11.102:1186;192.168.11.102:12346)/rpc.test?User=admin&password=123456");
Object count = testInf.getCount();
Object count = testInf.getCount();
获取192.168.11.102:1186返回的结果:
Object count_1186 = BaseSPIManager.getRPCResult("192.168.11.102", "1186", count);如果返回值是异常,那么直接抛出该异常。
或者
Object count_1186 = BaseSPIManager.getMinaRPCResult
("192.168.11.102:1186", count);如果返回值是异常,那么直接抛出该异常。
或者
Object count_1186 =
BaseSPIManager.getRPCResult("192.168.11.102:1186", count,
org.frameworkset.remote.Target.BROADCAST_TYPE_MINA); 如果返回值是异常,那么直接抛出该异常。
获取192.168.11.102:12346返回的结果:
Object count_12346 = BaseSPIManager.getRPCResult("192.168.11.102", "12346", count); 如果返回值是异常,那么直接抛出该异常。
或者
Object count_12346 = BaseSPIManager.getMinaRPCResult
("192.168.11.102:12346", count);
或者
Object count_12346 =
BaseSPIManager.getRPCResult("192.168.11.102:12346", count,
org.frameworkset.remote.Target.BROADCAST_TYPE_NETTY); 如果返回值是异常,那么直接抛出该异常。
- 远程服务协议-netty协议
- 远程服务协议介绍
- 远程服务协议介绍
- 远程服务调用协议-Jgroup协议配置
- 9.5.3远程服务协议-Mina协议
- 远程服务调用-JMS协议
- 9.5.5远程服务调用-Webservice协议
- Java远程服务调用协议对比
- 远程协议-RMI协议
- Netty自定义协议开发
- Netty-私有协议栈
- netty 私有协议开发
- netty自定义协议解码
- MessageToMessageDecoder netty自定义协议
- Netty 协议开发
- Netty私有栈协议
- netty实现webSocket协议
- netty自定义协议
- poj 1753 Flip Game
- 如何在LandaV8中使用跳出地段
- 链接交换 pr3 家居类
- Oracle内存全面分析(1)
- 在命令行输入EOF
- 远程服务协议-netty协议
- 编译SAM BA报错
- Windows上好用的十大开源软件 你用过了吗?(
- NC的使用
- vi/vim快捷键盘图
- 【数论 / 数值】【RQNOJ】最末非0位
- STM32的时钟系统分析
- PKU 1088
- ADC主要性能及其性能及其对接收机性能的影响