You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用JMS Template创建RabbitMQ及发送消息至队列报错406咨询

Fixing PRECONDITION_FAILED Error with RabbitTemplate & RabbitMQ's tempQueue

Hey there, let's tackle this error you're hitting. That ShutdownSignalException with reply-code 406 is RabbitMQ's way of saying: "The queue parameters your template is using don't match what I already have for tempQueue". Specifically, your existing queue has x-message-ttl, x-dead-letter-exchange, and x-dead-letter-routing-key set, but your template isn't including these arguments when it interacts with the queue.

Here's how to fix it:

1. Align Your Queue Declaration with Existing Parameters

If your application automatically declares the queue (Spring often does this by default), you need to ensure the declaration includes all the custom arguments you set up manually in RabbitMQ.

Java Configuration Example

@Bean
public Queue tempQueue() {
    Map<String, Object> queueArgs = new HashMap<>();
    // Replace these values with your actual queue parameters
    queueArgs.put("x-message-ttl", 300000); // 5 minutes in milliseconds
    queueArgs.put("x-dead-letter-exchange", "my-dlx-exchange");
    queueArgs.put("x-dead-letter-routing-key", "dlx-routing-key");

    // durable: true matches your existing queue's durability setting
    return new Queue("tempQueue", true, false, false, queueArgs);
}

XML Configuration Example

<rabbit:queue name="tempQueue" durable="true">
    <rabbit:queue-arguments>
        <entry key="x-message-ttl" value="300000" value-type="java.lang.Long"/>
        <entry key="x-dead-letter-exchange" value="my-dlx-exchange"/>
        <entry key="x-dead-letter-routing-key" value="dlx-routing-key"/>
    </rabbit:queue-arguments>
</rabbit:queue>

2. Disable Automatic Queue Declaration (If You Created It Manually)

If you already set up tempQueue directly in RabbitMQ and don't want your app to re-declare it (which causes the parameter mismatch), turn off automatic declaration:

Java Configuration

@Bean
public Queue tempQueue() {
    // Reference the existing queue without declaring it
    return new Queue("tempQueue", true, false, false, null);
}

@Bean
public RabbitAdmin rabbitAdmin(ConnectionFactory connectionFactory) {
    RabbitAdmin admin = new RabbitAdmin(connectionFactory);
    admin.setAutoStartup(false); // Prevent automatic queue declaration on startup
    return admin;
}

XML Configuration

<rabbit:queue name="tempQueue" durable="true" declare="false"/>

3. Double-Check Your Template Setup

Make sure your RabbitTemplate (note: RabbitMQ uses RabbitTemplate, not JmsTemplate—you might have mixed up terminology here) is pointing to the correct vhost and queue. Also, scan your codebase to ensure no other component is accidentally re-declaring tempQueue without the required arguments.

4. Clean Up and Re-Deploy (If Needed)

If you've tried the above and still see the error, delete the existing tempQueue from RabbitMQ first, then restart your application. This ensures your app creates the queue with the exact arguments you've configured, eliminating any leftover mismatches.

The root cause here is RabbitMQ's strict validation: when a client tries to declare an existing queue, every argument must match exactly. Either match your app's declaration to the queue's existing parameters, or stop declaring the queue entirely if you've already set it up manually.

内容的提问来源于stack exchange,提问作者Karthikeyan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:35:51