使用JMS Template创建RabbitMQ及发送消息至队列报错406咨询
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

