PHPackages                             wuwx/laravel-plus-amqp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. wuwx/laravel-plus-amqp

ActiveLibrary

wuwx/laravel-plus-amqp
======================

v1.7.1(3mo ago)095MITPHPCI passing

Since Aug 1Pushed 3mo ago1 watchersCompare

[ Source](https://github.com/wuwx/laravel-plus-amqp)[ Packagist](https://packagist.org/packages/wuwx/laravel-plus-amqp)[ RSS](/packages/wuwx-laravel-plus-amqp/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (7)Dependencies (3)Versions (8)Used By (0)

laravel-plus-amqp
=================

[](#laravel-plus-amqp)

Laravel AMQP 扩展，基于 PHP `ext-amqp` 提供连接、交换机、队列的简单管理与发布/消费封装。

特性
--

[](#特性)

- 通过配置统一管理 AMQP 连接、交换机与队列
- 首次使用时自动声明 exchange/queue，并完成 bindings
- 支持 Facade 与容器单例两种使用方式

环境要求
----

[](#环境要求)

- PHP 扩展：`ext-amqp`（`composer.json` 中为 suggest）
- Laravel 版本：`illuminate/support` ~5.1 或 ^6 ~ ^12

安装
--

[](#安装)

```
composer require wuwx/laravel-plus-amqp
```

### 服务提供者

[](#服务提供者)

Laravel 5.5+ 会自动发现服务提供者：

- `Wuwx\LaravelPlusAmqp\LaravelPlusAmqpServiceProvider`

Laravel 5.4 及以下版本需手动注册：

```
// config/app.php
'providers' => [
    Wuwx\LaravelPlusAmqp\LaravelPlusAmqpServiceProvider::class,
],

'aliases' => [
    'Amqp' => Wuwx\LaravelPlusAmqp\AmqpFacade::class,
],
```

### 发布配置

[](#发布配置)

```
php artisan vendor:publish --tag=config
```

发布后配置文件位于：`config/amqp.php`。

快速上手
----

[](#快速上手)

1. 安装扩展并确保 `ext-amqp` 可用
2. 发布配置并设置连接信息
3. 使用 Facade 发布/消费消息

### 示例环境变量

[](#示例环境变量)

```
AMQP_HOST=127.0.0.1
AMQP_PORT=5672
AMQP_VHOST=/
AMQP_LOGIN=guest
AMQP_PASSWORD=guest
```

配置说明
----

[](#配置说明)

默认配置来自 `config/amqp.php`：

```
return [
    'defaults' => [
        'connection' => 'default',
        'exchange' => 'default',
        'queue' => 'default',
    ],
    'connections' => [
        'default' => [
            'host' => env('AMQP_HOST', 'localhost'),
            'port' => env('AMQP_PORT', 5672),
            'vhost' => env('AMQP_VHOST', '/'),
            'login' => env('AMQP_LOGIN', 'guest'),
            'password' => env('AMQP_PASSWORD', 'guest'),
        ],
    ],
    'exchanges' => [
        'default' => [
            'connection' => 'default',
            'name'       => 'exchange_name',
            'type'       => 'topic',
            'flags'      => AMQP_DURABLE,
        ],
    ],
    'queues' => [
        'default' => [
            'connection' => 'default',
            'bindings' => [
                ['exchange_name', 'routing_key'],
            ],
        ],
    ],
];
```

- `connections` 数组会作为 `AMQPConnection` 的参数传入。
- `exchanges` 首次调用时会自动声明（`declareExchange`）。
- `queues` 首次调用时会自动声明并执行 `bindings`（`bind`）。
- `bindings` 结构为 `[exchange, routing_key]`，等价于 `$queue->bind($exchange, $routingKey)`。

使用方式
----

[](#使用方式)

包内通过容器单例 `amqp` 提供管理器，也提供 Facade：`Wuwx\LaravelPlusAmqp\AmqpFacade`。

### 发布消息

[](#发布消息)

```
use Wuwx\LaravelPlusAmqp\AmqpFacade as Amqp;

Amqp::publish(
    'payload',
    'routing.key',
    AMQP_NOPARAM,
    ['content_type' => 'text/plain']
);
```

### 消费消息

[](#消费消息)

```
use Wuwx\LaravelPlusAmqp\AmqpFacade as Amqp;

Amqp::consume(function ($message, $queue) {
    // 处理消息
    $queue->ack($message->getDeliveryTag());
});
```

> `publish` 与 `consume` 的参数会直接透传给 `AMQPExchange::publish` 与 `AMQPQueue::consume`， 具体参数请参考 `ext-amqp` 文档。

### 使用指定连接/交换机/队列

[](#使用指定连接交换机队列)

```
$manager = app('amqp');

$connection = $manager->connection('default');
$exchange = $manager->exchange('default');
$queue = $manager->queue('default');

$exchange->publish('payload', 'routing.key');
```

项目结构
----

[](#项目结构)

```
.
├── config
│   └── amqp.php              # 默认配置
├── src
│   ├── AmqpFacade.php         # Facade
│   ├── AmqpManager.php        # 管理器（connection/exchange/queue）
│   └── LaravelPlusAmqpServiceProvider.php
├── tests
│   └── TestCase.php
└── composer.json

```

开发与测试
-----

[](#开发与测试)

```
vendor/bin/phpunit
```

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance82

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~518 days

Recently: every ~764 days

Total

7

Last Release

96d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9c1977bba4586c70a4bdb6faaee4823184904ff3bd3246e79069871465500611?d=identicon)[wuwx](/maintainers/wuwx)

---

Top Contributors

[![wuwx](https://avatars.githubusercontent.com/u/4401?v=4)](https://github.com/wuwx "wuwx (17 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wuwx-laravel-plus-amqp/health.svg)

```
[![Health](https://phpackages.com/badges/wuwx-laravel-plus-amqp/health.svg)](https://phpackages.com/packages/wuwx-laravel-plus-amqp)
```

###  Alternatives

[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
