Dead-letter queue used by the RABBITMQ project

Source: Internet
Author: User
Tags rabbitmq

Message consumption failure processing method:

One entry into the dead letter queue (three ways to enter Badmail)

1. Message rejected (Basic.reject or basic.nack) and Requeue=false

2. Message TTL Expiration Expiration time

3. queue reaches Maximum length

DLX, too. Normal Exchange is no different from general exchange, it can be specified on any queue, in effect setting the properties of a queue, and when there is a dead letter in the queue, RABBITMQ automatically republish the message to the set of exchange. , which in turn is routed to another queue, publish can listen to the message in this queue to do the corresponding processing, this feature can compensate R ABBITMQ 3.0.0 previously supported immediate parameters to publish confirm function.



Three modes of RABBITMQ:

I. Fanout Exchange Broadcast

All messages sent to Fanout Exchange are forwarded to all the queue with that Exchange binding (binding). Fanout Exchange does not need to process routekey. You simply need to bind the queue to exchange. This way, messages sent to Exchange are forwarded to all the queues that are bound to the switch. Similar to subnet broadcasts, each host in the network receives a copy of the message. Therefore, Fanout Exchange forwarding messages are the fastest.

Two. Direct Exchange Point-to-point

All messages sent to direct Exchange are forwarded to the queue specified in Routekey. Direct mode, you can use RABBITMQ's own Exchange:default Exchange. Therefore, you do not need to bind exchange for any binding (binding) operations. When the message is delivered, the Routekey must match exactly to be received by the queue, or the message will be discarded.

Three. Topic Exchange fuzzy Matching

All messages sent to topic Exchange are forwarded to all of the queues that are concerned with the topic specified in Routekey, and Exchange will routekey and a topic for fuzzy matching. At this point the queue needs to bind a topic. You can use wildcard characters for fuzzy matching, the symbol "#" matches one or more words, and the symbol "*" matches not many words. So "log.#" is able to match to "Log.info.oa", but "log.*" matches only to "Log.error". Therefore, Topic Exchange is very flexible to use.

Dead-letter Queue implementations:

See website Description: http://www.rabbitmq.com/ttl.html

Use the x parameter to define message TTL for a queue during a declaration

For example: Spring is configured as follows:

<rabbit:connection-factory id= "ConnectionFactory" host= "47.104.203.101" password= "admin"
Username= "admin" port= "5672"
Channel-cache-size= "virtual-host="/citpay "
Publisher-confirms= "true"
Publisher-returns= "true"/>


<rabbit:template id= "Amqptemplate" connection-factory= "ConnectionFactory" mandatory= "true"
confirm-callback= "Payorderconfirmcallback"
return-callback= "Payorderreturncallback"/>

<rabbit:admin connection-factory= "ConnectionFactory"/>

<rabbit:queue id= "Pay_order_queue" name= "Citpay.pay_order_queue" durable= "true" auto-delete= "false" >
<rabbit:queue-arguments>
<entry key= "X-message-ttl" >
<value type= "Java.lang.Long" >5000</value>
</entry>
<entry key= "X-dead-letter-exchange" >
<value type= "Java.lang.String" >citpay.pay_order_dead_exchange</value>
</entry>
</rabbit:queue-arguments>
</rabbit:queue>

<rabbit:direct-exchange name= "Citpay.direct_pay_order_exchange" id= "Direct_pay_order_exchange" durable= "true" Auto-delete= "false" >
<rabbit:bindings>
<rabbit:binding queue= "Citpay.pay_order_queue" key= "Pay_order_routekey"/>
</rabbit:bindings>
</rabbit:direct-exchange>

<rabbit:queue id= "Pay_dead_order_queue" name= "Citpay.pay_dead_order_queue" durable= "true" auto-delete= "false" ></rabbit:queue>

<rabbit:direct-exchange name= "Citpay.pay_order_dead_exchange" id= "Pay_order_dead_exchange" durable= "true" Auto-delete= "false" >
<rabbit:bindings>
<rabbit:binding queue= "Citpay.pay_dead_order_queue" key= "Pay_order_routekey"/>
</rabbit:bindings>
</rabbit:direct-exchange>


<rabbit:listener-container
connection-factory= "ConnectionFactory" acknowledge= "Manual" max-concurrency= "1" >
<rabbit:listener queues= "Citpay.pay_dead_order_queue"
ref= "Payorderdeadreceiveconfirmlistener"/>
</rabbit:listener-container>



using policies to define queue TTL for queues
  Command form:
Rabbitmqctl set_policy Expiry ". * "' {" Expires ": 1800000} '- apply-to queues

Management Console Settings Policy:



Dead-letter queue used by the RABBITMQ project

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.