Spring RMI 配置和使用以及带均衡策略时client端的配置

client端:

a.不带均衡策略


<bean id="galaxyReportRemoteInterface_0" class="org.springframework.remoting.rmi.RmiProxyFactoryBean" lazy-init="true">
      <property name="serviceUrl"><value>${rmi.report1}</value></property>
      <property name="serviceInterface" value="com.sogou.earth.web.report.rmi.GalaxyReportRemoteInterface"></property>
      <property name="lookupStubOnStartup" value="false"/>
      <property name="refreshStubOnConnectFailure" value="true"/>
      <property name="registryClientSocketFactory" ref="rmiSocketFactory" />
   </bean>

<bean id="rmiSocketFactory" class="net.sf.ehcache.distribution.ConfigurableRMIClientSocketFactory">
    <constructor-arg index="0"><value>${rmi.timeout}</value></constructor-arg>
   </bean>


b.带均衡策略(RoundRobinStrategy 轮循)

<bean id="galaxyReportRemoteInterfaceSelector" class="com.sogou.earth.web.report.rmi.GalaxyReportRemoteInterfaceSelectorImpl" lazy-init="true">
      <property name="rmiSelectStrategy" ref="rmiSelectStrategy"></property>
      <property name="targets">
        <map>
          <entry key="galaxyReportRemoteInterface_0" value-ref="galaxyReportRemoteInterface_0"/>
          <entry key="galaxyReportRemoteInterface_1" value-ref="galaxyReportRemoteInterface_1"/>
        </map>
       </property>
    </bean>
<bean id="rmiSelectStrategy" class="com.sogou.earth.web.report.rmi.RoundRobinStrategy" lazy-init="true">
<constructor-arg>
<map key-type="java.lang.String" value-type="java.lang.Integer">
<entry key="galaxyReportRemoteInterface_0" value="1" />
<entry key="galaxyReportRemoteInterface_1" value="1" />
</map>
</constructor-arg>
</bean>


   <bean id="galaxyReportRemoteInterface_0" class="org.springframework.remoting.rmi.RmiProxyFactoryBean" lazy-init="true">
      <property name="serviceUrl"><value>${rmi.report1}</value></property>
      <property name="serviceInterface" value="com.sogou.earth.web.report.rmi.GalaxyReportRemoteInterface"></property>
      <property name="lookupStubOnStartup" value="false"/>
      <property name="refreshStubOnConnectFailure" value="true"/>
      <property name="registryClientSocketFactory" ref="rmiSocketFactory" />
   </bean>


   <bean id="galaxyReportRemoteInterface_1" class="org.springframework.remoting.rmi.RmiProxyFactoryBean" lazy-init="true">
      <property name="serviceUrl"><value>${rmi.report2}</value></property>
      <property name="serviceInterface" value="com.sogou.earth.web.report.rmi.GalaxyReportRemoteInterface"></property>
      <property name="lookupStubOnStartup" value="false"/>
      <property name="refreshStubOnConnectFailure" value="true"/>
      <property name="registryClientSocketFactory" ref="rmiSocketFactory" />
   </bean>
   
   <bean id="rmiSocketFactory" class="net.sf.ehcache.distribution.ConfigurableRMIClientSocketFactory">
    <constructor-arg index="0"><value>${rmi.timeout}</value></constructor-arg>
   </bean>


服务端:


<bean id="galaxyReportRemoteInterface" class="com.sogou.galaxy.report.rmi.GalaxyReportRemoteInterfaceImpl" autowire="byName" />

    <bean class="org.springframework.remoting.rmi.RmiServiceExporter">
        <property name="serviceName" value="galaxyReportRemoteInterface"></property>
          <property name="service">
              <ref local="galaxyReportRemoteInterface"/>
          </property>
          <property name="serviceInterface" value="com.sogou.earth.web.report.rmi.GalaxyReportRemoteInterface">
          </property>
        <property name="registryPort"><value>${rmi.stub.business.port}</value></property>
    </bean>





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值