Hot questions for Using RabbitMQ in apache camel

Top Java Programmings / RabbitMQ / apache camel


I hope someone can provide some help on this matter.

I am using camel rabbitmq and for testing purpose I am trying to send a message to the queue, which I'm trying to display in rabbitmq interface and then also read it back.

However I can't get this working.

What I believe works is that I created, in the exchange tab of rabbitmq management interface, a new exchange. In my java code I send the message to that exchange. When the code is executed, I can see a spike in the web interface showing that something has been received but I can't see what has been received. When I try to read, I can't read and get the following errror: < in route: Route(route2)[[From[rabbitmq:// because of Route route2 has no output processors. You need to add outputs to the route such as to("log:foo").

Can someone provide me a practical example on how to send a message,see it in the web interace and also read it? any tutorial showing this process will be also appreciated.

Thank you

================= SECOND PART

The error I'm getting now is the following:

Caused by: com.rabbitmq.client.ShutdownSignalException: channel error; reason: {#method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - cannot redeclare exchange 'rhSearchExchange' in vhost '/' with different type, durable, internal or autodelete value, class-id=40, method-id=10), null, ""}
    at com.rabbitmq.utility.ValueOrException.getValue(
    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(
    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(
    at com.rabbitmq.client.impl.AMQChannel.privateRpc(
    at com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc(
    ... 47 more

I have the following settings:

I get this error, I believe I’m doing something wrong with the URI and I have to define some extra parameters that I’m missing My exchange is of direct type My queue is of durable type And my uri is : rabbitmq://

any input on this?



So I was able to figure this out yesterday, I had the same (or at least similar) problems you were having.

The options you have in the RabbitMQ URI must exactly match the options that your exchange was created with. For example, in my configuration, I had an exchange called tasks that was a direct type, was durable, and was not configured to autodelete. Note that the default value for the autodelete option in the rabbitmq camel component is true. Additionally, I wanted to get the messages with the routing key camel. That means my rabbitmq URI needed to look like:


Additionally, I wanted to read from an existing queue, called task_queue rather than have the rabbitmq camel component declare it's own queue. Therefore, I also needed to add an additional query parameter, so my rabbitmq URI was


This configuration worked for me. Below, I added some Java code snippets from the code that configures the exchange and queue and sends a message, and my Camel Route configuration.

Exchange and Queue configuration:
rabbitConnFactory = new ConnectionFactory();
final Connection conn = rabbitConnFactory.newConnection();
final Channel channel = conn.createChannel();

// declare a direct, durable, non autodelete exchange named 'tasks'    
channel.exchangeDeclare("tasks", "direct", true); 
// declare a durable, non exclusive, non autodelete queue named 'task_queue'
channel.queueDeclare("task_queue", true, false, false, null); 
// bind 'task_queue' to the 'tasks' exchange with the routing key 'camel'
channel.queueBind("task_queue", "tasks", "camel"); 
Sending a message:
channel.basicPublish("tasks", "camel", MessageProperties.PERSISTENT_TEXT_PLAIN, "hello, world!".getBytes());
Camel Route:
public void configure() throws Exception {

I hope this helps!


I'm trying to write a SpringBootTest to test a Camel route. My route looks like this:


            .log("Hello!: ${body}");

Here's my test:

public class SimpleCamelRouteTest extends CamelTestSupport {

@EndpointInject(uri = "mock:rest")
private MockEndpoint mockEndpoint;

CamelContext context;

ProducerTemplate template;

public void setUp() throws Exception {

    context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
        public void configure() throws Exception {


public void test() throws InterruptedException {
    String body = "Camel";

    template.sendBody("mock:foo", body);



It looks like it is trying to connect to a real running instance of RabbitMq on booting :(

18-08-2019 13:20:07.729 [Camel (camel-1) thread #3 - RabbitMQConsumer] INFO - Connection failed, will retry in 5000ms Connection refused (Connection refused)

Can anybody offer me some advise on how to tell my SpringBootTest not to look for a running broker and to respect the mocks I have set up (assuming the mocks are set up correctly.)



You are trying to intercept consumer (from) with interceptSendToEndpoint. This is not possible. For this you need replaceFromWith.

context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
    public void configure() throws Exception {

And then trigger the route like this:

template.sendBody("direct:triggerFoo", body);

Also you are intercepting http4 producer, but from your route it seems you probably want to intercept rest* instead.


I have a spring application that uses camel for setting up a route to consume from a queue. I use rabbitmq as the message broker. Now the problem is that if the rabbitmq broker falls the connection is not autmatically recovered. I tried enabling automaticRecoveryEnabled. But I get noSuchMethodError. I'll show the code used to create connection.

<camelContext xmlns="">
        <propertyPlaceholder id="properties" location="file:data/rabbitmq/"/>
            <from uri="rabbitmq://{{}}:{{mete.rabbitmq.port}}/{{}}
            <to uri="stream:out"/>
            <process ref="myProcessor"/>

Below is the stack trace

Exception in thread "main" java.lang.NoSuchMethodError: com.rabbitmq.client.ConnectionFactory.setAutomaticRecoveryEnabled(Z)V
    at org.apache.camel.component.rabbitmq.RabbitMQEndpoint.getOrCreateConnectionFactory(
    at org.apache.camel.component.rabbitmq.RabbitMQEndpoint.connect(
    at org.apache.camel.component.rabbitmq.RabbitMQConsumer.openConnection(
    at org.apache.camel.component.rabbitmq.RabbitMQConsumer.doStart(
    at org.apache.camel.impl.DefaultCamelContext.startService(
    at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRouteConsumers(
    at org.apache.camel.impl.DefaultCamelContext.doStartRouteConsumers(
    at org.apache.camel.impl.DefaultCamelContext.safelyStartRouteServices(
    at org.apache.camel.impl.DefaultCamelContext.doStartOrResumeRoutes(
    at org.apache.camel.impl.DefaultCamelContext.doStartCamel(
    at org.apache.camel.impl.DefaultCamelContext.access$000(
    at org.apache.camel.impl.DefaultCamelContext$
    at org.apache.camel.impl.DefaultCamelContext$
    at org.apache.camel.impl.DefaultCamelContext.doWithDefinedClassLoader(
    at org.apache.camel.impl.DefaultCamelContext.doStart(
    at org.apache.camel.impl.DefaultCamelContext.start(
    at org.apache.camel.spring.SpringCamelContext.maybeStart(
    at org.apache.camel.spring.SpringCamelContext.onApplicationEvent(
    at org.apache.camel.spring.CamelContextFactoryBean.onApplicationEvent(
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(
    at rabbitmqClient.AbstractConsumer.openAMQPConnection(
    at rabbitmqClient.ConsumerPoolExecutor.startConsumer(
    at medagate.MedagateContext.main(


Error occurred because of the amqp-client dependency. When the version is changed from 2.8.4 to 3.5.1 the code works fine. New dependency is :