Spring远程处理RMI,客户端故障切换到备用服务器

Spring远程处理RMI,客户端故障切换到备用服务器,spring,rmi,spring-remoting,Spring,Rmi,Spring Remoting,Env:springframework3.2.3.0版本 在直接的spring上下文配置中,有没有一种方法可以通过RmiProxyFactoryBean或任何其他方法实现故障切换 我有一个服务器a作为主服务器,服务器B作为备用RMI服务器。如果与服务器A的连接已断开,则RMI调用应定向到服务器B。我已覆盖刷新和尝试查找方法RMIProxyFactoryBean,以实现此故障切换 @Override protected Object refreshAndRetry(MethodInvoca

Env:springframework3.2.3.0版本

在直接的spring上下文配置中,有没有一种方法可以通过RmiProxyFactoryBean或任何其他方法实现故障切换


我有一个服务器a作为主服务器,服务器B作为备用RMI服务器。如果与服务器A的连接已断开,则RMI调用应定向到服务器B。

我已覆盖
刷新和尝试
查找方法
RMIProxyFactoryBean
,以实现此故障切换

@Override
    protected Object refreshAndRetry(MethodInvocation invocation)   throws Throwable {

        if (logger.isDebugEnabled()) {
            logger.debug("Refreshing & retrying remote invocation.");
        }

        swapHitURLs();//Swap primary<>secondary URL

        return super.refreshAndRetry(invocation);
    }

@Override
    protected Remote lookupStub() throws RemoteLookupFailureException {
        Remote stub=null;

        if (logger.isDebugEnabled()) {
            logger.debug("Looking up the stub.");
        }

        try{
            stub=super.lookupStub();
        }catch(RemoteLookupFailureException rlfx){
            swapHitURLs();//Swap primary<>secondary URL
            if (logger.isDebugEnabled()) {
                logger.debug("Looking up the stub for swapped URL.");
            }
            stub=super.lookupStub();
        }

        return stub;
    }
@覆盖
受保护对象刷新和重试(MethodInvocation调用)抛出可丢弃的{
if(logger.isDebugEnabled()){
debug(“刷新并重试远程调用”);
}
swapHitURLs();//交换主要次要URL
返回super.refreshAndRetry(调用);
}
@凌驾
受保护的远程lookupStub()引发RemoteLookupFailureException{
远程存根=空;
if(logger.isDebugEnabled()){
debug(“查找存根”);
}
试一试{
stub=super.lookupStub();
}捕获(RemoteLookupFailureException rlfx){
swapHitURLs();//交换主要次要URL
if(logger.isDebugEnabled()){
debug(“在存根中查找交换的URL”);
}
stub=super.lookupStub();
}
返回存根;
}
配置XML:

<bean id="beanName" class="com.ahamed.poc.rmi.FailOverRMIProxyFactory" lazy-init="true">
    <property name="serviceUrl" value="PrimaryURL"/>
    <property name="alternativeServiceUrl" value="SecondaryURL"/>
    <property name="serviceInterface" value="com.ahamed.poc.rmi.InterfaceClass"/>
</bean> 

如果有更好的选择,请告诉我