2

Env : Spring Framework 3.2.3.RELEASE

簡単なスプリング コンテキスト構成でフェイルオーバーを実現する方法はありRmiProxyFactoryBeanますか?

ServerA をプライマリとして、ServerB を代替 RMI サーバーとして使用しています。ServerA への接続がダウンしている場合、RMI 呼び出しは ServerB に向けられる必要があります。

4

1 に答える 1

1

このフェールオーバー スイッチングを実現する方法をオーバーライドしrefreshAndRetryました。lookupStubRMIProxyFactoryBean

@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;
    }

構成 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> 

より良いオプションがあれば教えてください。

于 2013-12-29T11:41:59.070 に答える