PHPackages                             siujyu/think-nsq-queue - 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. siujyu/think-nsq-queue

ActiveLibrary

siujyu/think-nsq-queue
======================

nsq client for thinkphp

1.0(6mo ago)01Apache-2.0PHP

Since Oct 23Pushed 6mo agoCompare

[ Source](https://github.com/allen1706/think-nsq-queue)[ Packagist](https://packagist.org/packages/siujyu/think-nsq-queue)[ RSS](/packages/siujyu-think-nsq-queue/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

think-nsq-queue for ThinkPHP6
=============================

[](#think-nsq-queue-for-thinkphp6)

安装
--

[](#安装)

> composer require annon/think-nsq-queue

配置
--

[](#配置)

> 配置文件位于 `config/nsq.php`

创建任务类
-----

[](#创建任务类)

> 推荐使用 `app\job` 作为任务类的命名空间 也可以放在任意可以自动加载到的地方

任务类不需继承任何类，如果这个类只有一个任务，那么就只需要提供一个`fire`方法就可以了，如果有多个小任务，就写多个方法，下面发布任务的时候会有区别
每个方法会传入两个参数 `annon\queue\job\NSQJob $job`（当前的任务对象） 和 `$data`（发布任务时自定义的数据）

还有个可选的任务失败执行的方法 `failed` 传入的参数为`$data`（发布任务时自定义的数据）

### 下面写个例子

[](#下面写个例子)

```
namespace app\job;

use annon\queue\job\NSQJob;

class Job1 {
    public function fire(Job $job, $data) {

        //....这里执行具体的任务

        if ($job->attempts() > 3) {
             //通过这个方法可以检查这个任务已经重试了几次了
        }

        //如果任务执行成功后 记得删除任务，不然这个任务会重复执行，直到达到最大重试次数后失败后，执行failed方法
        $job->delete();

        // 也可以重新发布这个任务
        $job->release($delay); //$delay为延迟时间
    }

    public function failed($data) {
        // ...任务达到最大重试次数后，失败了
    }
}
```

```
namespace app\job;

use annon\queue\job\NSQJob;

class Job2 {
    public function task1(Job $job, $data) {

    }

    public function task2(Job $job, $data) {

    }

    public function failed($data) {

    }
}
```

发布任务
----

[](#发布任务)

> `annon\queue\Queue::push($job, $data = '', $queue = null)`，发布后立即执行

> `annon\queue\Queue::later($delay, $job, $data = '', $queue = null)`，在`$delay`毫秒后执行

`$job` 是任务名
命名空间是`app\job`的，比如上面的例子一,写`Job1`类名即可
其他的需要些完整的类名，比如上面的例子二，需要写完整的类名`app\lib\job\Job2`
如果一个任务类里有多个小任务的话，如上面的例子二，需要用@+方法名`app\lib\job\Job2@task1`、`app\lib\job\Job2@task2`

`$data` 是你要传到任务里的参数

`$queue` 队列名，指定这个任务是在哪个队列上执行，同下面监控队列的时候指定的队列名,可不填

监听任务并执行
-------

[](#监听任务并执行)

```
php think nsq:listen
```

两种，具体的可选参数可以输入命令加 `--help` 查看

> 可配合supervisor使用，保证进程常驻

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance66

Regular maintenance activity

Popularity1

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 85.7% 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

Unknown

Total

1

Last Release

207d ago

### Community

Maintainers

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

---

Top Contributors

[![wanganfu](https://avatars.githubusercontent.com/u/12389683?v=4)](https://github.com/wanganfu "wanganfu (6 commits)")[![allen1706](https://avatars.githubusercontent.com/u/34757825?v=4)](https://github.com/allen1706 "allen1706 (1 commits)")

### Embed Badge

![Health badge](/badges/siujyu-think-nsq-queue/health.svg)

```
[![Health](https://phpackages.com/badges/siujyu-think-nsq-queue/health.svg)](https://phpackages.com/packages/siujyu-think-nsq-queue)
```

###  Alternatives

[topthink/think

the new thinkphp framework

8.0k1.2M13](/packages/topthink-think)[topthink/think-queue

The ThinkPHP6 Queue Package

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

Swoole extend for thinkphp

477174.4k19](/packages/topthink-think-swoole)[topthink/think-captcha

captcha package for thinkphp

132934.4k68](/packages/topthink-think-captcha)[topthink/think-worker

workerman extend for thinkphp

202227.2k9](/packages/topthink-think-worker)[topthink/think-migration

96460.8k121](/packages/topthink-think-migration)

PHPackages © 2026

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