定制 caylof/php-queue 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

caylof/php-queue

最新稳定版本:1.0.1

Composer 安装命令:

composer require caylof/php-queue

包简介

a simple php queue base on workerman and redis stream

README 文档

README

used with workerman and redis stream.

Example

example
 - process.php
 - client.php
 - consumers
   - TestPrint.php
  • make a test consumer
# consumers/TestPrint.php

namespace Caylof\Examples\Consumer;

use Caylof\Queue\ConsumerInterface;

class TestPrint implements ConsumerInterface
{
    public function getQueue(): string
    {
        return 'test1';
    }

    public function handle(array $data): void
    {
        if (mt_rand(0, 10) > 5) {
            throw new \Exception('test error');
        }
        var_dump($data);
    }
}
  • queue process server
# process.php

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/consumers/TestPrint.php';

use Workerman\Worker;

Worker::$pidFile = __DIR__ . '/test_queue-pid';
Worker::$logFile = '/dev/null';
Worker::$statusFile = '/dev/null';
$worker = new Worker();
$worker->count = 1;

$worker->onWorkerStart = function(Worker $worker) {
    $redis = new Redis();
    $redis->connect('192.168.110.116', 16379);

    $logger = new \Monolog\Logger('queue');
    $logger->pushHandler(new \Monolog\Handler\StreamHandler(__DIR__ . '/queue.log'));

    $handler = new \Caylof\Queue\RedisStreamProcess(
        \Illuminate\Container\Container::getInstance(),
        $redis,
        $logger,
        __DIR__ . '/consumers',
        'Caylof\\Examples\\Consumer',
    );
    $handler->onWorkerStart();
};

Worker::runAll();

run server:

php process.php start
  • client send message
# client.php

require __DIR__ . '/../vendor/autoload.php';

$redis = new Redis();
$redis->connect('192.168.110.116', 16379);

$client = new \Caylof\Queue\RedisStreamClient($redis);
$client->send('test1', ['id'=> 1, 'name' => 'cctv']);

run client:

php client.php

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-28