PHPackages                             kwm/think-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. [Queues &amp; Workers](/categories/queues)
4. /
5. kwm/think-amqp

ActiveLibrary[Queues &amp; Workers](/categories/queues)

kwm/think-amqp
==============

基于 ThinkPHP 6 的 RabbitMQ 消息队列 AMQP 操作类

v1.1.3(5y ago)73821[1 issues](https://github.com/kwm/think-amqp/issues)Apache-2.0PHPPHP &gt;=7.1.0

Since Nov 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/kwm/think-amqp)[ Packagist](https://packagist.org/packages/kwm/think-amqp)[ RSS](/packages/kwm-think-amqp/feed)WikiDiscussions master Synced today

READMEChangelog (6)Dependencies (1)Versions (7)Used By (0)

Think AMQP
==========

[](#think-amqp)

基于 ThinkPHP 6 的 RabbitMQ 消息队列 AMQP 操作类

安装
--

[](#安装)

> 该操作类需要依赖 PHP 的 AMQP 扩展，可使用 `pcel install amqp` 安装

```
composer require kwm/think-amqp

```

安装完成后，请确认 `vendor/services.php` 中数组里有添加 `think\\amqp\\Service`。若没有添加，请手工运行：`php think service:discover`

入门
--

[](#入门)

#### 配置

[](#配置)

将 [示例配置文件](example/config/amqp.php) 复制到项目 `config` 目录下

#### 生产者

[](#生产者)

```
\think\Container::pull('exchange')
->set('kwm')
->publish('message');
```

若交换机不存在，默认会创建 `fanout` 交换机，需要你在管理界面绑定对应的队列，比如将 `kwm` 交换机和 `kwm.queue` 队列绑定到一起

#### 消费者

[](#消费者)

```
$mq = \think\Container::pull('queue')
    ->set('kwm.queue');
$mq->setPrefetchCount(1); //一次只取一条消息
$mq->consume(function (\AMQPEnvelope $msg, \AMQPQueue $queue){
    //...
    if (处理成功) {
        $queue->ack($msg->getDeliveryTag());
    } else {
        $queue->nack($msg->getDeliveryTag()); // 不确认，下次会再推送该消息
    }
});
```

#### 消费者封装

[](#消费者封装)

```
\think\amqp\Consumer::exec('kwm.queue', function (\AMQPEnvelope $msg, \AMQPQueue $queue, $deathCount){
    return true; //消费成功，返回其他都会认为是失败
})
```

封装特性：

- 支持设置最大次数的失败自动重试
- 重试可自定义延时时间

#### 消费者命令行

[](#消费者命令行)

##### 配置

[](#配置-1)

1. 配置文件： `app/tasks.php`，内容请见 [这里](example/app/tasks.php)
2. 启动消费者：`php think consumer kwm`

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 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 ~74 days

Recently: every ~93 days

Total

6

Last Release

1993d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dfcd1bcfe557f15eb52833bbff0115ef978cee4c3a19aacdba760e743d6a6d3c?d=identicon)[kwm](/maintainers/kwm)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/kwm-think-amqp/health.svg)

```
[![Health](https://phpackages.com/badges/kwm-think-amqp/health.svg)](https://phpackages.com/packages/kwm-think-amqp)
```

###  Alternatives

[topthink/think-queue

The ThinkPHP6 Queue Package

640675.0k75](/packages/topthink-think-queue)

PHPackages © 2026

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