When an ApsaraMQ for RabbitMQ client calls exchangeDeclare, the broker checks whether an exchange with the same name already exists. If it does, the broker compares the properties in the declaration against the existing exchange. When any property differs, the broker closes the channel and returns an ExchangeHasDiffFields error.
Error message format
ExchangeHasDiffFields[ODurable=true&NDurable=false;]The error message identifies the mismatched properties:
O (Original) -- the property value of the existing exchange on the broker.
N (New) -- the property value in your declaration code.
In this example, the existing exchange has durable=true, but the declaration specifies durable=false.
Properties that can cause a mismatch
| Property | Type | Description |
|---|---|---|
exchange | String | The exchange name. |
type | String | Exchange routing behavior: fanout (broadcast to all bound queues), direct (exact routing key match), or topic (pattern-based routing key match). |
durable | boolean | Whether the exchange is automatically restored when the client reconnects to the ApsaraMQ for RabbitMQ broker. When set to true, the exchange is restored on reconnection, which is suitable for long-running business scenarios with high reliability requirements such as financial transaction notification and order processing. When set to false, the exchange is not restored, which is suitable for temporary business scenarios with low reliability requirements such as tests and short-term tasks. Default: true when created through the CreateExchange API or the Exchanges page in the ApsaraMQ for RabbitMQ console. |
autoDelete | boolean | Whether the exchange is deleted after the last queue unbinds from it. Default: false. |
internal | boolean | Whether the exchange is an internal exchange. When set to true, the exchange is bound to another exchange. When set to false, the exchange is bound to a queue. Default: false. |
arguments | Map | Optional parameters such as an alternate exchange. |
How to fix it
Option 1: Match your declaration to the existing exchange (recommended)
Look up the properties of the existing exchange, then update your declaration code to match.
Step 1: Check the existing exchange properties.
Do one of the following:
Open the Exchanges page in the ApsaraMQ for RabbitMQ console and find the exchange.
Call the ListExchanges API operation to retrieve exchange details programmatically.
Step 2: Update the declaration in your code.
For example, if the existing exchange has durable=true but your code declares durable=false:
// Before: durable=false conflicts with the existing exchange (durable=true)
channel.exchangeDeclare("test", "direct", false, false, false, null);
// After: set durable=true to match the existing exchange
channel.exchangeDeclare("test", "direct", true, false, false, null);The exchangeDeclare parameters are: (exchange, type, durable, autoDelete, internal, arguments). Align each parameter with the values returned by the console or the ListExchanges API.
Option 2: Delete and re-create the exchange
If the existing exchange has incorrect properties, delete it and re-create it with the properties your application needs.
Deleting an exchange removes all its bindings. Re-bind queues after you re-create the exchange.
Delete the exchange from the Exchanges page in the ApsaraMQ for RabbitMQ console, or call the corresponding API operation.
Run your application. The
exchangeDeclarecall creates the exchange with the properties specified in your code.Re-establish any queue bindings that were removed.