Search code examples
spring-bootrabbitmqapache-camelspring-camel

ApacheCamel is not creating a queue on RabbitMQ


I am following a tutorial, on using SpringBoot ApacheCamel with RabbitMQ I am at the stage, where I just want to create a queue

the code is as follows

@SpringBootApplication
@ComponentScan(basePackages = {"com.cav.routes"})
public class CamelApacheMicroServiceAApplication {

    public static void main(String[] args) {
        SpringApplication.run(CamelApacheMicroServiceAApplication.class, args);
    }

}
@Configuration
public class CamelConfiguration {

    
    // name as rabbitConnectionFactory camel will autoimport it
    @Bean
    public ConnectionFactory rabbitConnectionFactory() {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setPort(5672);
        factory.setUsername("guest");
        factory.setPassword("guest");
        return factory;
    }
}

@Component
public class WeatherRouter extends RouteBuilder{
    
    
     public static final String RABBIT_URI = "rabbitmq:amq.direct?queue=weather&routingKey=weather&autoDelete=false";

    @Override
    public void configure() throws Exception {
        // TODO Auto-generated method stub
        //define camel route
        //rabbitmq:exchange
        from(RABBIT_URI)
        .log(ERROR, "Got this message from RabbitMQ: ${body}");
    }

}

As I understand it the command

from("rabbitmq:amq.direct?queue=weather&routingKey=weather&autoDelete=false")

Should create a queue called weather

But when I look at my rabbitmq a queue has not been created

my pom is I am using java 17 with camel 3.7.3, which maybe the problem.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.0.8</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.cav.routes</groupId>
    <artifactId>CamelApacheMicroServiceA</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>CamelApacheMicroServiceA</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel.springboot</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
            <version>3.7.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-rabbitmq</artifactId>
            <version>3.7.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-rabbitmq</artifactId>
            <version>3.7.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-jackson</artifactId>
            <version>3.7.3</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

Thank you for any help


Solution

  • See on this webpage:

    https://github.com/apache/camel-spring-boot-examples/blob/main/rabbitmq/src/main/resources/application.properties

    # turn on auto declare so the exchange, queues are automatic created if not already present in rabbitmq broker
    camel.component.spring-rabbitmq.auto-declare = true