# RabbitMQ（二）AMQP协议mandatory和immediate标志位区别

mandatory和immediate是AMQP协议中basic.pulish方法中的两个标志位，它们都有当消息传递过程中不可达目的地时将消息返回给生产者的功能。具体区别在于：

1. mandatory标志位

2. immediate标志位

    die_on_error(amqp_basic_publish(conn,
1,
amqp_cstring_bytes(exchange),
amqp_cstring_bytes(routingkey),
1,   //mandatory标志位,消息不能到达队列则返回basic.return
0,   //immediate标志位,消息不能到达消费者返回basic.return
&props,
amqp_cstring_bytes(messagebody)),
"Publishing");

./amqp_sendstring localhost 5672 amq.direct jfy test
method.id=003C0032,method.name=AMQP_BASIC_RETURN_METHOD
Return.message=test

    die_on_error(amqp_basic_publish(conn,
1,
amqp_cstring_bytes(exchange),
amqp_cstring_bytes(routingkey),
0,   //mandatory标志位,消息不能到达队列则返回basic.return
1,   //immediate标志位,消息不能到达消费者返回basic.return
&props,
amqp_cstring_bytes(messagebody)),
"Publishing");

./amqp_sendstring localhost 5672 amq.direct jfy test
method.id=003C0032,method.name=AMQP_BASIC_RETURN_METHOD
Return.message=test

“{amqp_error,not_implemented,"immediate=true",'basic.publish'}”

Removal of "immediate" flag
What changed? We removed support for the rarely-used "immediate" flag on AMQP's basic.publish.
Why on earth did you do that? Support for "immediate" made many parts of the codebase more complex, particularly around mirrored queues. It also stood in the way of our being able to deliver substantial performance improvements in mirrored queues.
What do I need to do? If you just want to be able to publish messages that will be dropped if they are not consumed immediately, you can publish to a queue with a TTL of 0.
If you also need your publisher to be able to determine that this has happened, you can also use the DLX feature to route such messages to another queue, from which the publisher can consume them.