binsoul/net-mqtt-client-react
Composer 安装命令:
composer require binsoul/net-mqtt-client-react
包简介
Asynchronous MQTT client built on React
README 文档
README
This package provides an asynchronous MQTT client built on the React socket library. All client methods return a promise which is fulfilled if the operation succeeded or rejected if the operation failed. Incoming messages of subscribed topics are delivered via the "message" event.
Install
Via composer:
$ composer require binsoul/net-mqtt-client-react
Example
Connect to a public broker and run forever.
<?php declare(strict_types=1); use BinSoul\Net\Mqtt\Client\React\ReactMqttClient; use BinSoul\Net\Mqtt\Connection; use BinSoul\Net\Mqtt\DefaultMessage; use BinSoul\Net\Mqtt\DefaultSubscription; use BinSoul\Net\Mqtt\Message; use BinSoul\Net\Mqtt\Subscription; use React\Socket\DnsConnector; use React\Socket\TcpConnector; include 'vendor/autoload.php'; // Setup client $loop = \React\EventLoop\Loop::get(); $dnsResolverFactory = new \React\Dns\Resolver\Factory(); $connector = new DnsConnector(new TcpConnector($loop), $dnsResolverFactory->createCached('8.8.8.8', $loop)); $client = new ReactMqttClient($connector, $loop); // Bind to events $client->on( 'open', function () use ($client) { // Network connection established echo sprintf("Open: %s:%d\n", $client->getHost(), $client->getPort()); } ); $client->on( 'close', function () use ($client, $loop) { // Network connection closed echo sprintf("Close: %s:%d\n", $client->getHost(), $client->getPort()); $loop->stop(); } ); $client->on( 'connect', function (Connection $connection) { // Broker connected echo sprintf("Connect: client=%s\n", $connection->getClientID()); } ); $client->on( 'disconnect', function (Connection $connection) { // Broker disconnected echo sprintf("Disconnect: client=%s\n", $connection->getClientID()); } ); $client->on( 'message', function (Message $message) { // Incoming message echo 'Message'; if ($message->isDuplicate()) { echo ' (duplicate)'; } if ($message->isRetained()) { echo ' (retained)'; } echo ': ' . $message->getTopic() . ' => ' . mb_strimwidth($message->getPayload(), 0, 50, '...'); echo "\n"; } ); $client->on( 'warning', function (Exception $e) { echo sprintf("Warning: %s\n", $e->getMessage()); } ); $client->on( 'error', function (Exception $e) use ($loop) { echo sprintf("Error: %s\n", $e->getMessage()); $loop->stop(); } ); // Connect to broker $client->connect('broker.hivemq.com')->then( function () use ($client) { // Subscribe to all topics $client->subscribe(new DefaultSubscription('/#')) ->then( function (Subscription $subscription) { echo sprintf("Subscribe: %s\n", $subscription->getFilter()); } ) ->catch( function (Exception $e) { echo sprintf("Error: %s\n", $e->getMessage()); } ); // Publish humidity once $client->publish(new DefaultMessage('sensors/humidity', '55%')) ->then( function (Message $message) { echo sprintf("Publish: %s => %s\n", $message->getTopic(), $message->getPayload()); } ) ->catch( function (Exception $e) { echo sprintf("Error: %s\n", $e->getMessage()); } ); // Publish a random temperature every 10 seconds $generator = function (): int { return random_int(-20, 30); }; $onProgress = function (Message $message) { echo sprintf("Publish: %s => %s\n", $message->getTopic(), $message->getPayload()); }; $client->publishPeriodically(10, new DefaultMessage('sensors/temperature'), $generator, $onProgress) ->catch( function (Exception $e) { echo sprintf("Error: %s\n", $e->getMessage()); } ); } ); $loop->run();
Testing
$ composer test
License
The MIT License (MIT). Please see License File for more information.
binsoul/net-mqtt-client-react 适用场景与选型建议
binsoul/net-mqtt-client-react 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 793.83k 次下载、GitHub Stars 达 48, 最近一次更新时间为 2015 年 11 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「client」 「net」 「mqtt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 binsoul/net-mqtt-client-react 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 binsoul/net-mqtt-client-react 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 binsoul/net-mqtt-client-react 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The library provides us with a frame to build a workflow or a business process such as BPMN. Could execute tasks in parallel or delayed tasks
Multishipping support for the Mollie Payment Module for Magento 2
Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment But
A simple Laravel Library to connect/publish/subscribe to MQTT broker
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
统计信息
- 总下载量: 793.83k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 51
- 点击次数: 28
- 依赖项目数: 46
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-11-22