biigle/laravel-round-robin-queue

此包已被弃用且不再维护。未建议替代包。

适用于多个队列连接的循环负载均衡队列

v1.1.2 2020-03-31 06:10 UTC

This package is auto-updated.

Last update: 2020-11-09 12:36:03 UTC


README

Laravel或Lumen中多个队列连接的循环负载均衡队列。

与多个biigle/laravel-remote-queue连接配合良好。

Build Status

安装

composer require biigle/laravel-round-robin-queue

Laravel

Laravel会自动发现服务提供者。

Lumen

$app->register(Biigle\RoundRobinQueue\RoundRobinQueueServiceProvider::class);添加到bootstrap/app.php

设置

循环队列需要持久化缓存来正确工作。请确保您已设置缓存且不要使用array缓存。

使用

queue.connections中配置一个新的队列连接以使用类似以下的roundrobin驱动

// queue.connections
[
 'rr' => [
    'driver' => 'roundrobin',
    'queue' => 'default',
    'connections' => ['q1', 'q2'],
 ],
 'q1' => [/* ... */],
 'q2' => [/* ... */],
]

连接期望额外的配置选项queueconnectionsqueue选项设置新作业应推入的默认队列名称。connections选项设置用于负载均衡的其他队列连接。

每次您使用roundrobin驱动向队列推送新作业时,它将按循环方式转发到connections中配置的连接之一。示例

use Queue;

$queue = Queue::connection('rr');

$queue->push($job1); // Pushed to connection 'q1'.
$queue->push($job2); // Pushed to connection 'q2'.
$queue->push($job3); // Pushed to connection 'q1'.
$queue->push($job4); // Pushed to connection 'q2'.