1

I have an application using spring-boot, Apache Camel and active MQ. The camel routes are activeMQ queue polling routes.

This is the camel-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Configures the Camel Context-->

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:amq="http://activemq.apache.org/schema/core"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
       http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">

  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>file:${envpath}/activemqApplication.properties</value>

            </list>
        </property>
    </bean>


   <bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" init-method="start" destroy-method="stop">
        <property name="connectionFactory" ref="jmsConnectionFactory"/>
        <property name="maximumActiveSessionPerConnection" value="${message.sessions.per.connection}"/>
        <property name="maxConnections" value="${message.max.connections}"/>
    </bean>

    <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"   primary="true">
        <property name="brokerURL" value="${message.broker.url}"/>
        <property name="trustAllPackages" value="true"/>
    </bean>

    <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
        <property name="connectionFactory" ref="pooledConnectionFactory"/>
    </bean>

    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
        <property name="connectionFactory" ref="pooledConnectionFactory"/>
        <property name="transactionManager" ref="jmsTransactionManager"/>
        <property name="usePooledConnection" value="true"/>
        <property name="concurrentConsumers" value="${activemq.concurrency}" />
    </bean>



<bean id="fileSupport" class=" com.archive.app.module.helper.filesSupport">
</bean>


  <camelContext xmlns="http://camel.apache.org/schema/spring">
    <package>com.fileSupport.app.routes</package>

  </camelContext>

</beans>

These are the classes

Spring boot class

package com.fileSupport.app;

import org.springframework.boot.SpringApplication;

public final class FileSupportMain {

    public static void main(final String[] args) {
        SpringApplication app = new SpringApplication(FileArchiveSpringBootApplication.class);
        app.setWebEnvironment(false);
        app.run(args);
    }

    private FileSupportMain() {
    }
}

Spring boot main class

package com.fileSupport.app;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;

@ImportResource({"classpath:/META-INF/spring/camel-context.xml"})
@EnableConfigurationProperties

@SpringBootApplication
public  class FileSupportSpringBootApplication {
}



package com.fileSupport.app.routes;
import org.apache.camel.Exchange;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jackson.JacksonDataFormat;
import org.apache.camel.model.dataformat.JsonLibrary;
import org.springframework.stereotype.Component;

Camel Routes:

/**
 * ActiveMQ queue is watched by
 * this route which then performs content based
 * routing on the messages using XPath.
 */

@Component
public final class ConsumeActiveMQmessages extends RouteBuilder {

    @Override
    public void configure() throws Exception {


         from("activemq:queue:" + Variables.RECEIVE_QUEUE1)
             .routeId("queueRoute")

             .log(LoggingLevel.INFO, "Body: $simple{body}")
             .to("activemq:queue:" + Variables.RECEIVE_QUEUE2);

         from("activemq:queue:" + Variables.RECEIVE_QUEUE2)
         .to("direct:callback");

         from("direct:callback")

         .log(LoggingLevel.INFO, "body: $simple{body}")

         .end();

    }
}

1 Answer 1

0

If you are not using spring-boot-starter-web you should turn on the Camel run controller option.

See the docs for the option at: https://github.com/apache/camel/blob/master/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelConfigurationProperties.java#L124

You just configure this using normal spring boot configuration style.

1
  • 1
    Link in the answer is dead
    – dimirsen Z
    Sep 7, 2021 at 19:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.