0

I'm looking for a way to publish/subscribe messages/channels to a RabbitMQ mqtt over websockets broker from php, and I can't find any code, or any good libraries out there.

I found https://github.com/bluerhinos/phpMQTT but it looks like that's for MQTT, and not for MQTT-over-websockets, plus it looks abandoned.

Why is that so hard - I know I'm not the first person looking for that? Any suggestions?

Thank you

SudoPlz
  • 20,996
  • 12
  • 82
  • 123

1 Answers1

1

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.

Josh Woodcock
  • 2,683
  • 1
  • 22
  • 29
  • I'm using the https://www.rabbitmq.com/web-mqtt.html plugin, so I'm using RabbitMQ to serve mqtt over websockets. – SudoPlz Feb 20 '19 at 19:53
  • The reason we opted for MQTT was because we'll be sending messages back and forth to mobile devices, so we care about the battery consumption and the guaranty of delivery over unstable networks. – SudoPlz Feb 20 '19 at 19:55
  • You can still consume messages via AMQP in php – Josh Woodcock Feb 20 '19 at 19:56
  • Interesting, can you explain that a bit further please? I can use MQTT to publish and subscribe to messages on the mobile (client) and web app (client) side, and consume those messages on the php (server) side with AMQP ? – SudoPlz Feb 20 '19 at 19:57
  • Yes exactly https://www.rabbitmq.com/mqtt.html "Subscribers consume from RabbitMQ queues bound to the topic exchange." – Josh Woodcock Feb 20 '19 at 19:58
  • Woah, I had no idea thanks! I'll experiment with that. – SudoPlz Feb 20 '19 at 20:01