assegaiphp/rabbitmq 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

assegaiphp/rabbitmq

最新稳定版本:1.0.1

Composer 安装命令:

composer require assegaiphp/rabbitmq

包简介

RabbitMQ queue integration for AssegaiPHP framework, providing decorators and tools for producing and consuming AMQP-based jobs.

README 文档

README

Assegai Logo

Latest release Tests PHP 8.4+ License Status active

RabbitMQ queue driver for AssegaiPHP applications.

AssegaiPHP RabbitMQ Queue Integration

This package provides RabbitMQ queue support for the AssegaiPHP framework. It enables asynchronous job handling using AMQP through PhpAmqpLib.

Contribution workflow

For commit and pull request conventions in this repo, see:

📦 Installation

Install via Composer:

composer require assegaiphp/rabbitmq

RabbitMQ extension requirement

This package currently requires the PHP amqp extension.

If Composer stops with an error like this:

Root composer.json requires PHP extension ext-amqp * but it is missing from your system.

the problem is usually your local PHP CLI setup, not RabbitMQ itself.

Check the PHP environment Composer is using:

php --ini
php -m | grep amqp

If amqp is missing, install or enable it for the same PHP version that runs Composer.

On Debian or Ubuntu, that is often:

sudo apt install php-amqp

or a version-specific package such as:

sudo apt install php8.5-amqp

If your distribution does not provide a package yet, pecl is often the fallback:

sudo pecl install amqp

After that, confirm the extension is loaded with php -m | grep amqp and rerun Composer.

Avoid installing with --ignore-platform-req=ext-amqp for normal development. That bypasses Composer's check, but it does not make the extension available at runtime.

⚙️ Configuration

Update your application's config/queues.php file to register the RabbitMQ driver and define your connections:

<?php

use Assegai\Rabbitmq\RabbitMQQueue;

return [
  'drivers' => [
    'rabbitmq' => RabbitMQQueue::class,
  ],
  'connections' => [
    'rabbitmq' => [
      'notifications' => [
        'host' => 'localhost',
        'port' => 5672,
        'username' => 'guest',
        'password' => 'guest',
        'vhost' => '/',
        'exchange_name' => 'notifications',
        'routing_key' => 'notifications',
        'passive' => false,
        'durable' => true,
        'exclusive' => false,
        'auto_delete' => false,
      ],
    ],
  ],
];

📝 Note:

  • The drivers key maps queue driver names (like 'rabbitmq') to their fully qualified class names.
  • The connections key defines queue configurations by driver and queue name (e.g., 'rabbitmq.notifications').

✨ Usage

Producing Jobs

Inject the queue connection using the #[InjectQueue] attribute:

use Assegai\Common\Interfaces\Queues\QueueInterface;
use Assegai\Core\Attributes\Injectable;
use Assegai\Core\Queues\Attributes\InjectQueue;

#[Injectable]
readonly class NotificationsService
{
  public function __construct(
    #[InjectQueue('rabbitmq.notifications')] private QueueInterface $queue
  ) {
  }

  public function send(object $payload): void
  {
    $this->queue->add($payload);
  }
}

Consuming Jobs

Define an injectable processor class for the queue:

use Assegai\Core\Attributes\Injectable;
use Assegai\Core\Queues\Attributes\QueueProcessor;

#[Injectable]
#[QueueProcessor('rabbitmq.notifications')]
final class NotificationsProcessor
{
  public function process(object $job): void
  {
    // Handle the job here.
    // For example: send an email, call another service, or write to the database.
  }
}

Register that processor in your module's provider list so the CLI can discover it.

If you want a starter file instead of writing the class from scratch, you can scaffold one with:

assegai g qp notifications --queue=rabbitmq.notifications

If you already know the job class you want to handle, you can type the generated process(...) method too:

assegai g qp notifications --queue=rabbitmq.notifications --job=Jobs/NotificationJob

If the feature already has a local Jobs folder, you can also use a bare job name:

assegai g qp notifications --queue=rabbitmq.notifications --job=notification-job

Running the Worker

Use the Assegai queue commands to discover and run processors:

assegai queue:list
assegai queue:work rabbitmq.notifications

If you want to process one job and exit, use:

assegai queue:work rabbitmq.notifications --once

If more than one processor is registered for the same queue, pass --processor to pick one explicitly.

For more information on running workers, refer to the AssegaiPHP queue guide.

🧪 Testing

You can trigger jobs via your API or CLI and observe processing output in the worker terminal.

📚 Resources

Support

Assegai is an MIT-licensed open source project. It can grow thanks to sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Assegai is MIT licensed.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固