PHPackages                             huangbin2018/dbmq - 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. huangbin2018/dbmq

ActiveLibrary

huangbin2018/dbmq
=================

DB实现简单的消息队列

v1.0.1(6y ago)09MITPHPPHP &gt;=7.0

Since Dec 20Pushed 6y ago1 watchersCompare

[ Source](https://github.com/huangbin2018/dbmq)[ Packagist](https://packagist.org/packages/huangbin2018/dbmq)[ RSS](/packages/huangbin2018-dbmq/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

dbmq
====

[](#dbmq)

利用 MySQL 实现简单的 DB 消息队列。

安装
--

[](#安装)

Package is available on [Packagist](https://packagist.org/packages/huangbin2018/dbmq), 使用 Composer [Composer](http://getcomposer.org).

```
composer require huangbin2018/dbmq
```

### 依赖

[](#依赖)

- PHP 7.0+
- PDO Extension

使用
--

[](#使用)

### 消息发布

[](#消息发布)

首先创建tag，消费者key，再绑定两者的关系； 然后就可以发布消息了。

```
// Mysql 连接配置
$dbConfig = [
    'user' => 'root',
    'password' => '',
    'host' => '127.0.0.1',
    'port' => '3306',
    'database' => 'test',
];
$channel = 'test_channel';
$tag = 'test_tag';
$consumerArr = [
    'consumer_1',
    'consumer_2',
    'consumer_3',
    'consumer_4',
    'consumer_5',
] ;

// 实例化消息生产者
$publisherObj = new Publisher($channel, $dbConfig);

// 定义tag
$publisherObj->declareTag($tag, TagType::TOPIC, '测试tag');

// 定义消费者
foreach ($consumerArr as $consumerKey) {
    // 定义消费者
    $publisherObj->declareConsumer($consumerKey, '', '测试consumerKey');
    // 绑定tag
    $publisherObj->bindTag($consumerKey, $tag);
}

// 发布消息
$key = 'uid_1';
$data = [
    'user_id' => 1,
    'user_name' => 'huangbin',
];
$message = new Message($data);
$body = $message->serialize();
$rs = $publisherObj->send($tag, $key, $body);
```

### 消息消费

[](#消息消费)

```
use DBMQ\Message\Message;
use DBMQ\Consumer\Consumer;
use DBMQ\Message\Response;

// 数据库连接参数
$dbConfig = [
    'user' => 'root',
    'password' => '',
    'host' => '127.0.0.1',
    'port' => '3306',
    'database' => 'test',
];

$channel = 'test_channel';
$tag = 'test_tag';
$consumerKey = 'consumer_1';

$processSize = $argv[1] ?? 0; // 消费者进程数
$processIndex = $argv[2] ?? 0; // 进程索引
$consumerObj = new Consumer($consumerKey, $dbConfig, '', $processSize, $processIndex);

// 定义消息消费处理函数
$consumerObj->run(function (Message $message) {
    $timestamp = $message->getTimestamp();

    // 消息体
    $body = $message->getMessage();
    print_r($body);

    // 这里是逻辑处理...
    try {
        $ack = true;
        if ($ack == false) {
            $msg = '测试失败啦';
            return Response::isFail($msg);
        } else {
            $msg = '测试成功啦';
            return Response::isSuccess($msg);
        }
    } catch (\Exception $e) {
        // 异常
        return Response::isException($e->getMessage());
    }
});
```

只有有绑定了消费者的 tag 才能发布消息，否则消息不会被保存！！！

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Unknown

Total

1

Last Release

2336d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9979f6356775b5a3949ebe2639f8b4da61d58c691d15356c6c995ba0ed1cf491?d=identicon)[huangbin2018](/maintainers/huangbin2018)

---

Top Contributors

[![huangbin2018](https://avatars.githubusercontent.com/u/36786839?v=4)](https://github.com/huangbin2018 "huangbin2018 (6 commits)")

---

Tags

MQMySQL MQ

### Embed Badge

![Health badge](/badges/huangbin2018-dbmq/health.svg)

```
[![Health](https://phpackages.com/badges/huangbin2018-dbmq/health.svg)](https://phpackages.com/packages/huangbin2018-dbmq)
```

###  Alternatives

[queue-interop/queue-interop

Promoting the interoperability of MQs objects. Based on Java JMS

48030.5M87](/packages/queue-interop-queue-interop)[iron-io/iron_mq

Client binding for IronMQ (hosted message queue)

871.8M30](/packages/iron-io-iron-mq)[usmonaliyev/laravel-simple-rabbitmq

This package provides simple usage of rabbitmq.

778.7k](/packages/usmonaliyev-laravel-simple-rabbitmq)

PHPackages © 2026

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