zachariahyoung
zachariahyoung

Reputation: 831

Camel and Activemq setup with Spring Boot

I have noticed in several examples, the common way to configure activemq with camel is with the following beans. I would like to know if Spring Boot already configures any of these beans by default. I know that if the activemq jars are on the class path a default connection factory is created, but what about everything below?

<bean id="jmsConnectionFactory"
        class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="tcp://localhost:61616"/>
  </bean>

  <bean id="pooledConnectionFactory"
        class="org.apache.activemq.pool.PooledConnectionFactory"
        init-method="start" destroy-method="stop">
    <property name="maxConnections" value="8"/>
    <property name="connectionFactory" ref="jmsConnectionFactory"/>
  </bean>

  <bean id="jmsConfig"
        class="org.apache.camel.component.jms.JmsConfiguration">
    <property name="connectionFactory" ref="pooledConnectionFactory"/>
    <property name="concurrentConsumers" value="10"/>
  </bean>

  <bean id="jms"
        class="org.apache.activemq.camel.component.ActiveMQComponent">
    <property name="configuration" ref="jmsConfig"/>
    <property name="transacted" value="true"/>
    <property name="cacheLevelName" value="CACHE_CONSUMER"/>
  </bean>

or

@Bean
    public ActiveMQConnectionFactory getConnectionFactory() {
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
        connectionFactory.setBrokerURL(brokerURL);
        return connectionFactory;
    }

    @Bean(initMethod = "start", destroyMethod = "stop")
    public PooledConnectionFactory getPooledConnectionFactory() {
        PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory();
        pooledConnectionFactory.setMaxConnections(maxConnections);
        pooledConnectionFactory.setConnectionFactory(getConnectionFactory());
        return pooledConnectionFactory;
    }

    @Bean
    public JmsConfiguration getJmsConfiguration() {
        JmsConfiguration jmsConfiguration = new JmsConfiguration();
        jmsConfiguration.setConnectionFactory(getPooledConnectionFactory());
        return jmsConfiguration;
    }

    @Bean
    public JmsConfiguration getJmsHighPriorityConfiguration() {
        JmsConfiguration jmsConfiguration = new JmsConfiguration();
        jmsConfiguration.setConnectionFactory(getPooledConnectionFactory());
        jmsConfiguration.setPriority(8);
        return jmsConfiguration;
    }

    @Override
    protected void setupCamelContext(CamelContext camelContext) throws Exception {
        ActiveMQComponent activeMQComponent = new ActiveMQComponent();
        activeMQComponent.setConfiguration(getJmsConfiguration());
        camelContext.addComponent("activemq", activeMQComponent);

        ActiveMQComponent activeMQHighPriorityComponent = new ActiveMQComponent();
        activeMQHighPriorityComponent.setConfiguration(getJmsHighPriorityConfiguration());
        camelContext.addComponent("activemq-high-priority", activeMQHighPriorityComponent);
    }

Upvotes: 12

Views: 7638

Answers (1)

gtonic
gtonic

Reputation: 2313

Meanwhile there are some spring-boot-starters which can be used to have ActiveMQ and Camel running within Spring Boot.

ActiveMQ

Start with spring-boot-starter-activemq in your pom:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-activemq</artifactId>
</dependency>

Configuration

Have a look what's configurable through this at all - its documented in Appendix A. Common application properties (search for 'activemq' and 'jms').

Alternative approach: from my point of view, its best to determine what's configurable in Sprint Boot and what not is having a look at their auto-configuration mechanism:

Camel

Apache Camel provides its own Spring Boot integration. Basically you also have to add camel-spring-boot-starter:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-spring-boot-starter</artifactId>
    <version>2.17.3</version>
</dependency>

Configuration

I haven't found a good example configuration file, so again, have a look at configuration is exposed through CamelConfigurationProperties class.

In general - like you mentioned - you might end up in registering some of your beans manually if you don't find all properties exposed via this configuration.

Upvotes: 3

Related Questions