stcer / aint-queue-client
a client for aint-queue
0.0.1
2024-04-26 06:46 UTC
Requires
- php: >=7.2
- ext-json: *
- predis/predis: ^1.1
Suggests
- php: >=7.3
This package is auto-updated.
Last update: 2025-03-26 08:52:09 UTC
README
Aint Queue 是基于 Swoole 的一个异步队列库, 此项目是一个客户端, 用于向 Aint Queue服务器增加延时任务
Install
composer require stcer/aint-queue-client -vvv
Example
客户端增加延时任务示例, 参考example/demo-client.php
use Composer\Autoload\ClassLoader; use j\AintQueue\Client\AliasMessageEncoder; use j\AintQueue\Client\Driver\DriverFactory; use j\AintQueue\Client\Driver\Redis\Queue as RedisQueue; $loader = require __DIR__ . '/../vendor/autoload.php'; $channel = 'example'; $driverOption = [ 'class' => RedisQueue::class, 'connection' => [ 'host' => 'redis.jz.cn', 'port' => 6379, 'database' => '0', // 'password' => 'password', ], 'encoder' => AliasMessageEncoder::class, ]; /** @var RedisQueue $queue */ $queue = DriverFactory::make($channel, $driverOption); $queue->push('simple', 2); $queue->push([ 'simple', [ ['info_id' => 10] ] ], 5);
服务端配置示例
use Littlesqx\AintQueue\Driver\Redis\Queue as RedisQueue; use Littlesqx\AintQueue\Serializer\AliasMessageEncoder; use Stcer\AintQueueDemo\job\SimpleJob; return [ 'example' => [ 'driver' => [ 'class' => RedisQueue::class, 'connection' => [ 'host' => 'redis.jz.cn', 'port' => 6379, 'database' => '0', // 'password' => 'password', ], 'encoder' => function() { $encoder = new AliasMessageEncoder(); $encoder->addClassMap('NTY', SimpleJob::class); $encoder->addClassMap('simple', SimpleJob::class); return $encoder; }, ], 'logger' => [ 'class' => \Littlesqx\AintQueue\Logger\DefaultLogger::class, 'options' => [ 'level' => \Monolog\Logger::DEBUG, ], ], 'pid_path' => '/var/run/aint-queue', 'consumer' => [ 'sleep_seconds' => 1, 'memory_limit' => 96, 'dynamic_mode' => true, 'capacity' => 20, 'flex_interval' => 5 * 60, 'min_worker_number' => 5, 'max_worker_number' => 30, ], 'job_snapshot' => [ 'interval' => 5 * 60, 'handler' => [], ], ], ];