nailfor / php-queue-client
a queue broker client library for php
Installs: 1 274
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- react/socket: ^1.1
Requires (Dev)
- phpunit/phpunit: ^5.0.0
README
phpQueueClient is an client library for AMQP and MQTT queues server. Its based on the reactPHP socket-client
Goal
Goal of this project is easy to use both AMQP and MQTT client for PHP in a modern architecture without using any php modules. Original idea taken from https://github.com/oliverlorenz/phpMqttClient
-
yes it correctly supports both qos protocols
-
yes it works with huge data in a packet
-
yes it can receive, ping, unsubscribe and publish
-
Protocol specifications: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/csprd02/mqtt-v3.1.1-csprd02.html
Example publish
use nailfor\queue\ClientFactory; use nailfor\queue\protocol\MQTT; class MQTTClass { public function subscribe() { $url = '127.0.0.1:5672'; $options = [ //'username' => '', //'password' => '', 'clientId' => 'php', 'cleanSession' => false, 'topics' => [ 'topic_name' => [ //this flag clear message after reciev. Default true //'clear' => false, 'qos' => 1, //only for MQTT 'message' => 'hello from topic', ], 'capital_name' => [ 'qos' => 2, //only for MQTT 'message' => 'hello from capital', ], ], ]; $protocol = new MQTT; //default AMQP ClientFactory::publish($url, $options, [$this, 'onError'], $protocol); } }
Example subscribe
use nailfor\queue\ClientFactory; use nailfor\queue\protocol\MQTT; use Illuminate\Support\Facades\Log; class MQTTClass { public function onMessage($packet) { //... } public function onCapitalMessage($packet) { //... } public function onError($reason) { echo $reason->getMessage(). PHP_EOL; exit; } public function subscribe() { $url = '127.0.0.1:5672'; $options = [ //'username' => '', //'password' => '', 'clientId' => 'php', 'cleanSession' => false, 'topics' => [ 'topic_name' => [ //this flag clear message after reciev. Default true //'clear' => false, 'qos' => 1, //only for MQTT 'events' => [ 'PUBLISH' => [$this, 'onMessage'], ], ], 'capital_name' => [ 'qos' => 0, //only for MQTT 'events' => [ 'PUBLISH' => [$this, 'onCapitalMessage'], ], ], ], ]; $protocol = new MQTT; //default AMQP $logger = Log::channel('stderr'); //default null ClientFactory::run($url, $options, [$this, 'onError'], $protocol, $logger); } }
also commands are available
ClientFactory::run //subscribe and get messages
ClientFactory::publish
ClientFactory::unsubscribe
ClientFactory::ping
The Logger suppurt 3 level of details: notice, info and debug. Offcourse you can disable it set null in last param
Notice - (Oct 21th, 2020)
Currently work:
-
AMQP implementation:
-
publish.. not yet
-
subscribe
-
unsubscribe
-
MQTT implementation:
-
- qos 1
-
- qos 2
-
subscribe
-
unsubscribe
-
publish