最近我发布了一个在客户端实现RMI 负载均衡和支持故障转移的项目;地址在:
http://code.google.com/p/rmi-lb-client/
你可以用如下的方式使用它:
JAVA:
List<String> serviceUrls = new ArrayList<String>(); serviceUrls.add("rmi://localhost:8098/CalculatorRMIService"); serviceUrls.add("rmi://localhost:8099/CalculatorRMIService"); RmiLbServiceConfig<CalculatorService> config = new RmiLbServiceConfig <CalculatorService>(serviceUrls, CalculatorService.class); config.setMonitorPeriod(60L);//default 600 seconds config.setLookupStubOnStartup(true); // default is false; RmiProxyFactory factory = RmiProxyFactory.getInstance(); CalculatorService as = factory.create(config); Spring:
<bean id="CalculatorService" class="com.travelsky.rmilbclient.RmiProxyFactoryBean"> <property name="config"> <bean class="com.travelsky.rmilbclient.RmiLbServiceConfig"> <!-- ServiceUrls --> <property name="serviceUrls"> <list> <value>rmi://localhost:8098/CalculatorRMIService</value> <value>rmi://localhost:8099/CalculatorRMIService</value> </list> </property> <!-- service interface --> <property name="serviceInterface" value="calculator.CalculatorService" /> <!-- Lookup stub on startup? --> <property name="lookupStubOnStartup" value="false" /> <!-- Stub Status Monitor Period --> <property name="monitorPeriod" value="600" /> </bean> </property> </bean>
由于rmi端口问题,在server端实现比较困难,在client端实现相对容易和清晰,工程使用的是maven;有需要的,或者是发现bug,请给我联系;