鍍金池/ 問(wèn)答/PHP/ php rabbitmq 如何實(shí)現(xiàn)消費(fèi)者自動(dòng)觸發(fā)讀取消息

php rabbitmq 如何實(shí)現(xiàn)消費(fèi)者自動(dòng)觸發(fā)讀取消息

1、根據(jù)rabbitmq 官方文檔 搭建了一個(gè)測(cè)試 創(chuàng)建隊(duì)列 以及 發(fā)送消息 接受消息 但是都是 用 php server.php 和 php client.php 這樣的形式 來(lái)執(zhí)行的 如果部署到服務(wù)器 如何實(shí)現(xiàn) client.php 來(lái)自動(dòng)消費(fèi)這個(gè)隊(duì)列里面的消息 始終與服務(wù)器保持聯(lián)系
網(wǎng)上的一些資料是寫一個(gè)sell 腳本 以及while 循環(huán)來(lái)處理 不知道還有什么其他的方式。

回答
編輯回答
心沉

正常定時(shí)執(zhí)行 php client.php了

2018年1月15日 08:54
編輯回答
孤星
    public function receive($callback, $routingKey = null)
    {
        if (self::$connection === null) {
            $this->openConnection();
        }
        //channel
        $channel = new \AMQPChannel(self::$connection);
        $channel->setPrefetchCount($this->preFetchCount);
        $queue = new \AMQPQueue($channel);
        $queue->setName($this->queue);
        $queue->bind($this->exchange, empty($routingKey) ? $this->routingKey : $routingKey);
        while (true) {
            $queue->consume($callback);
        }
    }

參考一下。目前PHP只有while循環(huán)的形式(當(dāng)然,你可以考慮一下php的多線程)

2018年3月26日 12:36