11 Replies Latest reply on Feb 5, 2010 9:17 AM by andrew hurst

    failover prevents context from being created if unable to connect

    andrew hurst Newbie







      We are starting our application from Spring using the org.apache.camel.spring.Main.main() method passing in an XML configuration file.


      Within that config file we define a JmsComponent bean which connects to an activeMQ instance on another machine:




      We also define many other beans for the local application besides this one.


      We notice that if the "failover" uri is unable to connect to the "myExternalHost" activeMQ instance when the application is started, the ApplicationContext is not created and remains null.


      We know this because:


      Main.getInstance().getApplicationContext() returns null


      If we remove the "failover" uri and the tcp connection to "myExternalHost" is allowed to fail, then the context is created and the above code returns an ApplicationContext object.


      This is causing us major problems because the connection to "myExternalHost" is one of many beans we create at startup. All the other beans declared on the local application are created successfully and so the application begins processing so it appears that everything is working correctly. However when we try to get the ApplicationContext, it returns null and so in fact the application is not fully initialised, thus in an inconsistent state.


      As another note, if "myExternalHost" was available at application restart, we get our context without problem. If it then goes down after this point, the ApplicationContext is still valid (not null). So this proves that it is not necessary for the bean to have connected to get an ApplicationContext instance and so it should be the same at startup.


      Help appreciated.