Modification of PHP's MQ client acquisition queue method

Source: Internet
Author: User

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.

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.