首页 > 解决方案 > 如何在 PHP 中通过 websockets 代理向 mqtt 订阅/发布消息?

问题描述

我正在寻找一种通过 php 通过 websockets 代理向 RabbitMQ mqtt 发布/订阅消息/频道的方法,但我找不到任何代码或任何好的库。

我找到了https://github.com/bluerhinos/phpMQTT但它看起来是针对 MQTT 的,而不是针对 MQTT-over-websockets 的,而且它看起来已经被废弃了。

为什么这么难 - 我知道我不是第一个寻找它的人?有什么建议么?

谢谢

标签: phpmqttmqtt-over-websockets

解决方案


RabbitMQ uses AMQP not MQTT as a messaging protocol. Anyways there are several PHP RabbitMQ libraries out there that wrap the base phpamqplib library. You can of course use the MQTT plugin in which case the Mosquito library should work but I don't really understand why you would want to use MQTT instead of AMQP unless you have embedded devices publishing to your rabbitmq server. In this case you can still use AMQP for consuming messages with PHP.

My favorite PHP AMQP library is Bunny

Here is a benchmark of the different wrapper libraries out there: https://blog.forma-pro.com/php-amqp-clients-benchmark-them-all-8a4e6adb1a6b

amqp-ext is the fastest but it has to be installed into your php installation so I wouldn't recommend it unless you are already running tens of millions of messages a day and need a small performance gain will improve your costs.


推荐阅读