1.15.7.2 react/stomp
优质
小牛编辑
138浏览
2023-12-01
(要求Workerman版本>=3.3.6)
注意:此项目已经过期,无法使用,请勿安装
STOMP是一个通讯协议。它是支持大多数消息队列如RabbitMQ、Apollo等。
安装:
composer require react/stomp
示例:
<?php
require_once __DIR__ . '/vendor/autoload.php';
use WorkermanWorker;
$consumer = new Worker();
$consumer->onWorkerStart = function() {
global $client;
$loop = Worker::getEventLoop();
$factory = new ReactStompFactory($loop);
$client = $factory->createClient(array('vhost' => '/', 'login' => 'guest', 'passcode' => 'guest'));
$client
->connect()
->then(function ($client) use ($loop) {
$client->subscribe('/topic/foo', function ($frame) {
echo "Message received: {$frame->body}n";
});
});
};
Worker::runAll();
文档:
https://github.com/reactphp/stomp
注意:
1、所有的异步编码必须在onXXX
回调中编写
2、异步客户端需要的$loop
变量请使用Worker::getEventLoop();
返回值