Development tips

Restrict Spring bean inicialization 

If there are many Spring beans with route definitions then startup time for loading ESB application can be quite long. This functionality enables to include only those Spring beans which should be initialized or exclude those Spring beans which we don't want to initialize.

It can be handy during development because it's possible via system properties to restrict set of Spring beans (=Camel routes) which will be initialized.

More info in OpenHub configuration.

Calling services between Spring contexts

Common scenario for solving: there is root Spring context root and two child contexts for admin GUI (web MVC) and for web services (spring WS). And we need to call services in WS context from admin GUI controllers.

There is package of handful classes for solving this problem, see org.openhubframework.openhub.core.common.contextcall.ContextCall as main interface for use.

Routes initialization test 

If you want to test that all routes will be successfully initialized in Camel then use the following test. This test mainly checks that all routes have unique ID and URI.

 

/**
 * Test that verifies if all Camel routes are correctly initialized - if there are unique route IDs and unique URIs.
 *
 * @author <a href="mailto:petr.juza@openwise.com">Petr Juza</a>
 */
public class RoutesInitTest extends AbstractModulesDbTest {
    @BeforeClass
    public static void setInitAllRoutes() {
        setInitAllRoutes(true);
    }
    @Test
    public void testInit() {
        // nothing to do - if all routes are successfully initialized then test is OK
        System.out.println("All routes were successfully initialized");
    }
}

Annotations order is important

We use quite often annotations type of @ConditionalXXX or @AutoConfigureAfter/Before. Annotations @ConditionalOnBean/MissingBean/Class/MissingClass works quite fine but @AutoConfigureAfter/Before don't work at all.

Result is that only change in annotation order can go to non-functional or error state. 

Example:

public class CamelBootstrapConfiguration {
    // ...

    @Bean
    @ConditionalOnBean(ConnectionFactory.class)
    public CamelContextConfiguration jmsContextConfig(ConnectionFactory factory) {
        // configure jms component
    }

    // ...
}

The following works fine

@EnablePlaftormMessaging
@EnableIntegration
public class ApplicationConfiguration {
 // ...
}

... but this doesn't work - it stops during application start because JMS component is not configured. During Camel initialization is not configured messaging and therefore @ConditionalOnBean(ConnectionFactory.class) (use in @EnableXXX annotations) works in different way then we expect.

@EnableIntegration
@EnablePlaftormMessaging
public class ApplicationConfiguration {
 // ...
}