Gets the messages in MQ and then processes the failed retry mechanism:
The following code is the message code in the Getting queue queue for the PHP connection MQ client:
Public Function Createdurablesubscriber ($queue, $callback) {
&NBSP
$f = $this->con->subscribe ($queue);
while (1) {
$msg = $this->con->readframe ();
if ($msg!=null) {
echo "Received message with body ' $msg->body ' \ n";
$result = Call_user_func ($callback, $ msg);
& nbsp; //Bottom-level method interface Retrofit
//in the scenario where the interface is invoked, it is necessary to inform the consumed message after the calling interface is successful ( Call Ack method);
& nbsp; //If the calling interface fails, you need to keep the message and retry until the calling interface succeeds, consuming the message
//If the interface call fails, you still have to tell the consumed message (call Ack method) and retry the judgment elsewhere
$this->con->ack ($msg);
}
}
unset ($this->con);
}
Each time you push msg to the queue, you need to push an extra token retry_count. The initial value is 0.
After the failed to get MSG processing from the queue (the calling interface fails), the MSG needs to be pushed back to the queue, and the extra token retry_count plus 1, when retry_count=1;
And so on, each retry_count is added 1. Retry 10 times until retry_count=10, if processing fails, do not retry, but send rtx reminders to the responsible person.
The concept of recursion is used here.