承接 haider-kamran/laravel-mqtt 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

haider-kamran/laravel-mqtt

最新稳定版本:v1.0.0

Composer 安装命令:

composer require haider-kamran/laravel-mqtt

包简介

A production-ready Laravel package that integrates MQTT into Laravel applications in a clean, scalable, and event-driven way.

README 文档

README

MQTT Dashboard Latest Version on Packagist Total Downloads License

A production-ready, highly scalable, and developer-friendly Laravel package that integrates MQTT into your applications. It provides a clean, event-driven, "Horizon-like" architecture for managing IoT streams and long-running MQTT daemons safely.

🚀 Features

  • Clean Facade API: Effortless publishing and topic routing (Mqtt::publish, Mqtt::topic).
  • Event & Job Dispatching: Map incoming MQTT topics directly to Laravel Events or Jobs, pushing heavy processing to your Queues natively.
  • Robust Worker Daemon: Run php artisan mqtt:work under Supervisor with built-in memory protection, Graceful Shutdown (SIGTERM), and a Heartbeat Lock Manager to prevent duplicate processes.
  • Auto Reconnect & Backoff: Configurable exponential backoff strategies to handle broker disconnections professionally.
  • Topic Wildcards: Full support for MQTT wildcards (+ and #).
  • Native Broadcasting: Seamlessly integrates with Laravel's native Broadcasting (broadcast(new Event)->toOthers()) using the custom mqtt driver!
  • Premium Real-Time Dashboard: A built-in, Neo-Noir styled live metrics dashboard accessible out-of-the-box.
  • Strictly Typed: Built on PHP 8.1 Enums for QosLevel and Protocols.

📦 Requirements

  • PHP >= 8.1
  • Laravel >= 9.0

🛠 Installation

You can install the package via composer:

composer require haider-kamran/laravel-mqtt

The package will automatically register its service provider. You should publish the configuration file and dashboard assets using:

php artisan vendor:publish --tag=mqtt-config
php artisan vendor:publish --tag=mqtt-views

⚙️ Configuration

After publishing, you can configure your broker credentials and connection settings in config/mqtt.php or your .env file:

MQTT_HOST=127.0.0.1
MQTT_PORT=1883
MQTT_CLIENT_ID=laravel-app
MQTT_USERNAME=
MQTT_PASSWORD=
MQTT_PROTOCOL=3.1.1
MQTT_KEEP_ALIVE=60
MQTT_RECONNECT=true
MQTT_RECONNECT_MAX_DELAY=60

📚 Usage

Publishing Messages

You can easily publish messages to any MQTT broker using the Mqtt facade. Arrays are automatically JSON-encoded.

use Haiderkamran\LaravelMqtt\Facades\Mqtt;
use Haiderkamran\LaravelMqtt\Enums\QosLevel;

Mqtt::publish('device/1/cmd', ['reboot' => true]);

// With QoS and Retain flag
Mqtt::publish('device/status', 'online', QosLevel::EXACTLY_ONCE, true);

Subscribing & Routing Topics

To listen to inbound topics, register your routes within your AppServiceProvider or a custom provider's boot method.

You can map topics directly to Laravel Events or Jobs. If a topic matches, the payload will be automatically dispatched to Laravel's native queue ecosystem!

use Haiderkamran\LaravelMqtt\Facades\Mqtt;
use App\Events\TemperatureUpdated;
use App\Jobs\ProcessDeviceData;

public function boot()
{
    // Exact Match -> Dispatches a Laravel Event
    Mqtt::topic('sensor/temp')->event(TemperatureUpdated::class);

    // Wildcard Match -> Dispatches a Laravel Job to the Queue
    Mqtt::topic('device/#')->dispatch(ProcessDeviceData::class);
    
    // Single-level wildcard support
    Mqtt::topic('room/+/lights')->dispatch(ProcessLightCommand::class);
}

Running the Worker Daemon

To start listening for the routed topics, spin up the built-in worker command:

php artisan mqtt:work

This acts exactly like a Laravel Queue worker. In production, you should use Supervisor to keep this process alive. The worker uses Laravel's Cache system as a Mutex Lock to ensure multiple instances of the worker don't accidentally run at the same time and duplicate messages.

If your server crashes hard and the lock gets stuck, you can gracefully purge the state using:

php artisan mqtt:clear

Native Laravel Broadcasting

The package registers a custom mqtt broadcast driver. This means you can use Laravel's standard broadcasting mechanics to publish to MQTT topics!

In your .env:

BROADCAST_DRIVER=mqtt

Now, any Laravel Event that implements ShouldBroadcast will natively publish its payload directly to your MQTT broker, converting Laravel dot notation channels (private-user.1) to MQTT slash notation (private-user/1) automatically!

📈 Real-Time Dashboard

The package comes with a highly optimized, beautifully crafted live dashboard. Once installed, simply navigate to:

👉 http://your-app.test/mqtt

You will see real-time, glassmorphic metrics of Messages Received, Published, Connection Drops, and the active status of your Worker Daemon.

📄 License

The MIT License (MIT). Please see LICENSE.md for more information.

👨‍💻 Author

Built with ❤️ by Kamran Haider.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固