异步消息队列组件 - react/zmq
优质
小牛编辑
124浏览
2023-12-01
(要求Workerman版本>=3.3.6)
安装:
composer require react/zmq
示例:
<?php
require_once __DIR__ . '/vendor/autoload.php';
use WorkermanWorker;
$worker = new Worker('text://0.0.0.0:6161');
$worker->onWorkerStart = function() {
global $pull;
$loop = Worker::getEventLoop();
$context = new ReactZMQContext($loop);
$pull = $context->getSocket(ZMQ::SOCKET_PULL);
$pull->bind('tcp://127.0.0.1:5555');
$pull->on('error', function ($e) {
var_dump($e->getMessage());
});
$pull->on('message', function ($msg) {
echo "Received: $msgn";
});
};
Worker::runAll();
文档:
https://github.com/reactphp/zmq
注意:
1、所有的异步编码必须在onXXX
回调中编写
2、异步客户端需要的$loop
变量请使用Worker::getEventLoop();
返回值