react/stomp

(要求Workerman版本>=3.3.6)

STOMP是一个通讯协议。它是支持大多数消息队列如RabbitMQ、Apollo等。

安装:

  1. composer require react/stomp

示例:

  1. <?php
  2. require_once __DIR__ . '/vendor/autoload.php';
  3. use Workerman\Worker;
  4. $worker = new Worker('text://0.0.0.0:6161');
  5. $worker->onWorkerStart = function() {
  6. global $client;
  7. $loop = Worker::getEventLoop();
  8. $factory = new React\Stomp\Factory($loop);
  9. $client = $factory->createClient(array('vhost' => '/', 'login' => 'guest', 'passcode' => 'guest'));
  10. $client
  11. ->connect()
  12. ->then(function ($client) use ($loop) {
  13. $client->subscribe('/topic/foo', function ($frame) {
  14. echo "Message received: {$frame->body}\n";
  15. });
  16. });
  17. };
  18. Worker::runAll();

文档:

https://github.com/reactphp/stomp

注意:

1、所有的异步编码必须在onXXX回调中编写

2、异步客户端需要的$loop变量请使用Worker::getEventLoop();返回值