Objective:
As an operation and maintenance personnel do not back pot, who back it!
Body:
Online are 2 ways to achieve, the second I will not say, to upgrade rabbitmq Others also say what is not
OK ~ Today according to the online TTL + DLX Way to implement the delay message (Java Python related code has no Huang Film!!!!) )
Code:
1. First you have to create a new queue for the new switch to hold the delay message and set the new queue message TTL expires after forwarding the switch and routeing key (my old switch for e_test key for K1)
The main code is:
function Mqinityanchi ($e _name, $q _name, $k _route, $conn)
{
Creating Connections and Channel
$channel = new Amqpchannel ($conn);
To create a switch object
$ex = new Amqpexchange ($channel);
$ex->setname ($e _name);
$ex->settype (Amqp_ex_type_direct); Must be set
$ex->setflags (amqp_durable); Persistence does not have to be selected
echo "Exchange status:" $ex->declareexchange (). ' \ n ';
Binds the switch to the queue and specifies the routing key
Create a queue
$q = new Amqpqueue ($channel);
$q->setname ($q _name);
# $q->setflags (amqp_durable); Persistence of
$q->setargument (' X-dead-letter-exchange ', ' e_test '); Set TTL timeout forwarding to E_test
$q->setargument (' X-dead-letter-routing-key ', ' K1 '); Set TTL timeout to forward the key to K1
echo "Message total:". $q->declare (). " \ n ";
Echo ' Queue Bind: '. $q->bind ($e _name, $k _route). " \ n ";
return $ex;
}
2. That is, when the message is sent, set the TTL on the line. It's really simple.
Main code:
$message = "Test delay!";
$ex 1=mqinityanchi (' E_yanchi ', ' Q_yanchi ', ' K1 ', $conn);
$attributes = Array (' Expiration ' = 5000); Set to 5 Seconds
$ex 1->publish ($message, ' K1 ', ' 1 ', $attributes);
So that it can be sent to the Q_yanchi queue inside the message five seconds after expiration forwarded to the E_test-bound switch routing-key to the K1 queue.
It's a little rough to get off work. You can leave a message.
RABTTMQ PHP Delay message related code (online did not find themselves thinking about the fix)