elielelie/laravel-activemq
Composer 安装命令:
composer require elielelie/laravel-activemq
包简介
Laravel ActiveMQ driver
README 文档
README
This package enables usage of ActiveMQ (Stomp) driver for queueing natively inside Laravel.
Installation
composer require elielelie/laravel-activemq
In order to connect it to your queue you need to change queue connection driver in .env file:
QUEUE_CONNECTION=activemq
Variables:
ACTIVEMQ_PROTOCOL protocol (defaults to TCP)
ACTIVEMQ_HOST broker host (defaults to 127.0.0.1)
ACTIVEMQ_PORT port where STOMP is exposed in your broker (defaults to 61613)
ACTIVEMQ_USERNAME broker username (defaults to admin)
ACTIVEMQ_PASSWORD broker password (defaults to admin)
You can subscribe to queues to read from or to write to with:
ACTIVEMQ_QUEUE=...
default;email
You can see all other available .env variables, their defaults and usage explanation within the config file
You can publish the configuration file by running:
$ php artisan vendor:publish --provider="Elielelie\ActiveMQ\ActiveMQServiceProvider"
Usage
Dispatching Jobs
You can dispatch jobs to ActiveMQ just like any other Laravel queue driver:
use App\Jobs\ProcessOrder; // Dispatch to the default queue ProcessOrder::dispatch($order); // Dispatch to a specific queue ProcessOrder::dispatch($order)->onQueue('orders');
Delayed Jobs (Scheduling)
The driver supports delayed jobs using the later method or delay() helper:
// Delay job execution by 10 minutes ProcessOrder::dispatch($order)->delay(now()->addMinutes(10));
Message Persistence
By default, messages are sent according to the ACTIVEMQ_PERSISTENT environment variable.
- To ensure messages survive a broker restart, set
ACTIVEMQ_PERSISTENT=true. - If you need to override headers for a specific job, you can implement the
HasHeaderscontract in your Job class.
Health Check
You can verify the connection to the ActiveMQ broker using the healthCheck method on the connection:
use Illuminate\Support\Facades\Queue; $isConnected = Queue::connection('activemq')->healthCheck(); if (!$isConnected) { // Handle connection failure }
Failed jobs
For the sake of simplicity and brevity ActiveMQJob class is defined in a way to utilize Laravel tries and backoff properties out of the box (official documentation).
Upon failure, jobs will retry 5 times before being written to failed_jobs table.
Each subsequent attempt will be tried in attempt^2 seconds, meaning if it is a third attempt, it will retry in 9s after the previous job failure.
Note that job properties by default have precedence over CLI commands, thus with these defaults in place the flags --tries and --backoff will be overridden.
You can turn off this behavior with following .env variables:
ACTIVEMQ_AUTO_TRIES- defaults totrue. Set tofalseto revert to Laravel default of 0 retries.ACTIVEMQ_AUTO_BACKOFF- defaults totrue. Set tofalseto revert to Laravel default of 0s backoff.ACTIVEMQ_BACKOFF_MULTIPLIER- defaults to2. Does nothing ifACTIVEMQ_AUTO_BACKOFFis turned off. Increase to make even bigger interval between two failed jobs.
Job will be re-queued to the queue it came from.
Laravel Horizon Support
This package now supports Laravel Horizon for advanced queue management with multiple workers and auto-scaling capabilities.
Configuration
To enable Horizon support, add these environment variables:
ACTIVEMQ_HORIZON_ENABLED=true
ACTIVEMQ_HORIZON_ISOLATE=true
Horizon Configuration Example
Add this configuration to your config/horizon.php:
'environments' => [ 'production' => [ 'activemq-default' => [ 'connection' => 'activemq', 'queue' => ['default'], 'balance' => 'simple', 'processes' => 3, ], 'activemq-emails' => [ 'connection' => 'activemq', 'queue' => ['email'], 'balance' => 'auto', 'processes' => 2, 'maxProcesses' => 5, ], 'activemq-notifications' => [ 'connection' => 'activemq', 'queue' => ['notifications'], 'balance' => 'simple', 'processes' => 1, ], ], ],
Multiple Queue Setup
You can define multiple queues in your environment configuration:
ACTIVEMQ_QUEUE=default;email;notifications
Each supervisor in Horizon can process specific queues, allowing for:
- Worker Isolation: Different workers for different queue types
- Auto-Scaling: Automatic worker scaling based on queue load
- Priority Processing: Different process counts and strategies per queue
Balancing Strategies
- simple: Fixed number of workers distributed evenly
- auto: Dynamic worker allocation based on queue load
- false: Process queues in order without balancing
Logs
Logs are turned off by default. You can include them by setting env key ACTIVEMQ_LOGS=true.
In case you want to change the default log manager, it can be done in the log-activemq config file. The new log manager must extend Illuminate\Log\LogManager.
elielelie/laravel-activemq 适用场景与选型建议
elielelie/laravel-activemq 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.06k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「queue」 「php」 「stomp」 「activeMQ」 「driver」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 elielelie/laravel-activemq 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 elielelie/laravel-activemq 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 elielelie/laravel-activemq 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
STOMP bindings for React.
PHP AMQP Binding Library
A Laravel package to monitor queue jobs.
Laravel Stomp driver
Message Queue Stomp Transport
Message queue statistics for OroPlatform
统计信息
- 总下载量: 4.06k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-04