corley/queue

1.0.0 2017-01-21 09:22 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:42:24 UTC


README

可适应性队列层

Build Status Scrutinizer Code Quality Code Coverage

创建

$queue = new Queue("queue name", $queueAdapter);

也请查看wiki

可用适配器

从队列接收

list($receipt, $message) = $queue->receive();

// receive with options
list($receipt, $message) = $queue->receive(["timeout" => 15*60]);

在队列中发送

$queue->send("my message");

// send with options
$queue->send("my message", ["delay" => 20]);

从队列中删除

$queue->delete($receipt);

// delete with options
$queue->delete($receipt, ["delay" => 20]);

管理不同适配器的选项

仅使用函数

$queue = new Queue("https://sqs.amazon.com/39857/urs", $sqsAdapter);
$queue->send("message", toSQS(["delay" => 20]));

function toSQS(array options = []) {
    $opts = [];
    if (array_key_exists("delay", $options)) {
        $opts["DelaySeconds"] = $options["delay"];
    }
    return $opts;
}

队列接口(对于适配器)

您必须实现来自 Corley\Queue\QueueInterface 的3个方法

public function send($queueName, $message, array $options);
public function receive($queueName, array $options);
public function delete($queueName, $receipt, array $options);

关于返回值的提示(receive 消息)

如你所见,返回值

  • 发送操作应返回队列发送操作状态
  • 接收 必须 返回一个数组,其中第一个参数是需要用于删除操作的收据
  • 删除操作应返回队列删除操作状态