定制 aachich/message-broker 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

aachich/message-broker

Composer 安装命令:

composer require aachich/message-broker

包简介

AMQP Message Broker abstraction for Laravel - easily switch between RabbitMQ and other AMQP-compatible brokers

README 文档

README

Latest Version on Packagist PHP Version License

A Laravel package providing an abstraction layer for AMQP message brokers. Easily switch between RabbitMQ and other AMQP-compatible brokers without changing your application code.

Features

  • 🔄 Broker Abstraction - Switch message brokers without code changes
  • Fiber-based Async - Non-blocking publish/consume using PHP 8.1+ Fibers
  • 🔁 Automatic Retries - Configurable connection retry with exponential backoff
  • 📦 Bulk Publishing - Efficiently publish collections of messages
  • 💀 Dead Letter Queue - Automatic DLQ routing for failed messages
  • 🎯 Exchange Support - Publish to queues or exchanges with routing keys

Requirements

  • PHP 8.1+
  • Laravel 10.x or 11.x
  • RabbitMQ (or any AMQP-compatible broker)

Installation

composer require aachich/message-broker

The package will auto-register its service provider.

Publish Configuration

php artisan vendor:publish --provider="Aachich\MessageBroker\MessageBrokerServiceProvider" --tag=config

Environment Variables

Add these to your .env file:

RABBITMQ_HOST=localhost
RABBITMQ_PORT=5672
RABBITMQ_USER=guest
RABBITMQ_PASSWORD=guest
RABBITMQ_VHOST=/
RABBITMQ_QUEUE_CONSUMER=my-consume-queue
RABBITMQ_QUEUE_PUBLISHER=my-publish-queue
RABBITMQ_QUEUE_REJECT=my-dlq
RABBITMQ_MAX_RETRIES=30

Usage

Basic Publishing

use Aachich\MessageBroker\Facades\MessageBroker;

// Connect first
MessageBroker::connect();

// Publish a message
MessageBroker::publishToQueue($message, 'my-queue', ['header-key' => 'value']);

// Publish to an exchange
MessageBroker::publishToExchange($message, 'my-exchange', [], 'routing.key');

Consuming Messages

use Aachich\MessageBroker\Facades\MessageBroker;

MessageBroker::connect();

MessageBroker::consumeMessage('my-queue', function ($message) {
    // Process the message
    $body = $message->getBody();
    
    // Return true to acknowledge, false to reject
    return true;
});

Bulk Publishing

use Illuminate\Support\Collection;

$messages = collect(['msg1', 'msg2', 'msg3']);

MessageBroker::publishBulkMessagesToQueue($messages, 'my-queue');

Check Connection Status

$status = MessageBroker::getStatus();
// Returns: ['brokerName' => 'RabbitMQ', 'connect' => true, 'consuming' => false]

Extending with Custom Brokers

To add support for a new AMQP broker:

  1. Create a repository implementing BrokerRepoInterface:
use Aachich\MessageBroker\Contracts\BrokerRepoInterface;

class MyCustomBrokerRepository implements BrokerRepoInterface
{
    // Implement all interface methods
}
  1. Update the service provider binding based on config:
$this->app->singleton(BrokerRepoInterface::class, function ($app) {
    return match(config('messagebroker.default')) {
        'rabbitmq' => new RabbitMQRepository(),
        'custom' => new MyCustomBrokerRepository(),
        default => throw new InvalidMessageBrokerNameException(),
    };
});

Testing

vendor/bin/phpunit

Contributing

Contributions are welcome! Please submit a PR against the main branch.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This package is open-sourced software licensed under the MIT license.

aachich/message-broker 适用场景与选型建议

aachich/message-broker 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 02 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「queue」 「php」 「rabbitmq」 「AMQP」 「messaging」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 aachich/message-broker 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 aachich/message-broker 我们能提供哪些服务?
定制开发 / 二次开发

基于 aachich/message-broker 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-08