weldon/laravel-simple-rabbitmq
Composer 安装命令:
composer require weldon/laravel-simple-rabbitmq
包简介
This package provides simple usage of rabbitmq.
README 文档
README
laravel-simple-rabbitmq
The package for simplified RabbitMQ usage, supporting multiple connections, easy publishing, and consumer mode.
Documentation
Key Features
-
Multiple Connections: Effortlessly manage multiple RabbitMQ connections within the same application.
-
Exchange supporting: You can push messages to exchanges
-
Message Publishing: Easily publish messages to queues and exchange with a fluent, chainable syntax.
-
Consumer Mode: Enable consumers to receive and process messages from queues in real time.
-
Manage queues and exchanges in config file: You can register queues and exchanges in
config/simple-mq.phpand define them in easy way which isamqp:define-queuescommand.
Installation
You can install the package via composer:
composer require weldon/laravel-simple-rabbitmq
Next step you must publish config and action register files:
php artisan vendor:publish --provider="Weldon\SimpleRabbit\SimpleRabbitMQServiceProvider"
As a result of this command, you will have a configuration file config/simple-mq.php and a registry file
routes/amqp-handlers.php.
The config/simple-mq.php config file contains RabbitMQ connections with credentials, queues, default connection and
default queue.
The next stage is configure .env file.
SIMPLE_MQ_CONNECTION=
SIMPLE_MQ_QUEUE=
SIMPLE_MQ_HOST=
SIMPLE_MQ_PORT=
SIMPLE_MQ_USERNAME=
SIMPLE_MQ_PASSWORD=
Usage
The package can publish and consume messages
Publishing
You can publish a message with default connection and default queue:
<?php use Illuminate\Http\Request; use Weldon\SimpleRabbit\Facades\SimpleMQ; class FooController { public function createFoo(Request $request) { // Something.. SimpleMQ::queue('foo-queue') ->setBody(['name' => 'First Foo']) ->handler('create-foo') ->publish(); return response()->json(['message' => 'OK']); } }
Also, exchange function publish message to RabbitMq exchange:
<?php namespace App\Https\Controllers; use Illuminate\Http\Request; use Weldon\SimpleRabbit\Facades\SimpleMQ; class FooController { public function createFoo(Request $request) { // Something.. SimpleMQ::exchange('foo-exchange') ->setBody(['name' => 'First Foo']) ->handler('create-foo') ->publish(); return response()->json(['message' => 'OK']); } }
If you have multiply connection to RabbitMq, you can publish a message with connection method.
<?php namespace App\Https\Controllers; use Illuminate\Http\Request; use Weldon\SimpleRabbit\Facades\SimpleMQ; class FooController { public function createFoo(Request $request) { // Something.. SimpleMQ::connection('foo-connection') ->queue('foo-queue') ->setBody(['name' => 'First Foo']) ->handler('create-foo') ->publish(); return response()->json(['message' => 'OK']); } }
Consuming
Create app/AMQP/Handlers folder and create your handler classes.
For example:
<?php namespace App\AMQP\Handlers; use Weldon\SimpleRabbit\MQ\Message; class FooHandler { public function handle(Message $message) { // do something... $message->ack(); return ['ok' => true]; } }
Don't forget acknowledge message end of process, else consumer does not accept next message.
Then register your handler in routes/amqp-handlers.php file.
<?php use \App\AMQP\Handlers\FooHandler; use \Weldon\SimpleRabbit\Facades\ActionMQ; ActionMQ::register('create-foo', [FooHandler::class, 'handle']);
To consume messages use:
php artisan amqp:consume connection? queue?
The command requires two arguments which are connection and queue.
If you don't give them, command uses default connection and queue.
Plans
- Exchange configuration in
config/simple-mq.php - Setup testing.
Testing
composer test
License
The MIT License.
weldon/laravel-simple-rabbitmq 适用场景与选型建议
weldon/laravel-simple-rabbitmq 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 192 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「Simple」 「MQ」 「rabbit」 「weldon」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 weldon/laravel-simple-rabbitmq 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 weldon/laravel-simple-rabbitmq 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 weldon/laravel-simple-rabbitmq 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
AMQP module for Zend Framework 2 to integrate RabbitMQ
PHP's implementation of the library providing data synchronization between microservices
Integrates php-amqplib with RabbitMq and Nette Framework
A simple library for make Lexer and Parsers to build a language
A simple library that allows transform any kind of data to native php data or whatever
A simple library that uses the hydration pattern to fill objects given different sources of data.
统计信息
- 总下载量: 192
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-21