g41797/queue-sqs

针对 AWS SQS 的 Yii 队列适配器

v0.0.2 2024-06-22 11:14 UTC

This package is auto-updated.

Last update: 2024-09-22 11:54:46 UTC


README

tests

描述

Yii3 Queue Adapter for AWS SQS 是 Yii3 队列适配器家族中的新成员。

适配器的实现基于 enqueue/sqs 库。

要求

  • PHP 8.2 或更高版本。

安装

可以使用 composer 安装此包

composer require g41797/queue-sqs

通用用法

配置

默认配置

[
     'key' => null,                 // AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment.
     'secret' => null,              // AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment.
     'token' => null,               // AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment.
     'region' => us-east-1,         // (string, required) Region to connect to. See http://docs.aws.amazon.com/general/latest/gr/rande.html for a list of available regions.
     'retries' => 3,                // (int, default=int(3)) Configures the maximum number of allowed retries for a client (pass 0 to disable retries).
     'version' => 'latest',         // (string, required) The version of the webservice to utilize
     'profile' => null,             // (string, default=null) The name of an AWS profile to used, if provided the SDK will attempt to read associated credentials from the ~/.aws/credentials file.
     'queue_owner_aws_account_id'   // The AWS account ID of the account that created the queue.
]

Yandex 消息队列

根据 Yandex 博客

"...我们决定不为 Yandex 消息队列发明一个独特的接口,
而是实现 AWS SQS API 的支持,并且非常小心。"

这意味着 queue-sqs 支持 Yandex 消息队列,但这个用例尚未经过测试。

LocalStack 使用

LocalStack 允许 "...在本地开发和测试您的 AWS 应用程序,以减少开发时间...".

queue-sqs 的开发和测试使用了 LocalStack。

凭证

LocalStack 不需要 AWS 凭证。功能测试使用以下凭证

[
    'key' => 'anyKey',
    'secret' => 'noSecrets',
]

端点

AWS SDK for PHP 自动构建所需的 SQS 端点。

在 LocalStack 中,“硬编码”的端点保存在 phpunit 配置文件中

    <php>
        <ini name="error_reporting" value="-1"/>
        <env name="ENDPOINT" value="https://.localstack.cloud:4566" force="true" />
    </php>

queue-sqs 检查 ENDPOINT 的存在,并根据需要启动 AWS 库。

身份验证令牌

身份验证令牌 用于身份验证和检索您的 LocalStack 许可证。

您可以在 启动脚本 中看到示例

export LOCALSTACK_AUTH_TOKEN="ls-KESiVaLi-4697-7857-MEna-ziqIXeSaf962"

将此令牌替换为您自己的。

限制

作业状态

作业状态

// Push a job into the queue and get a message ID.
$id = $queue->push(new SomeJob());

// Get job status.
$status = $queue->status($id);

不支持。

SQS 限制

您可以在 Amazon SQS 常见问题解答 中找到很多信息

频道名称

  • 长度限制为 75 个字符
  • 只包含字母数字字符、连字符 (-) 和下划线 (_)

跨区域/账户通信

不支持跨区域/账户通信。

长轮询

工作者使用轮询超时从 SQS 获取消息(作业)。由于客户为每次接收付费,建议使用长值作为此超时。最大值为 20 秒,此值也用于零超时。

更多信息请参阅 Amazon SQS 短轮询和长轮询

许可证

Yii3 Queue Adapter for AWS SQS 是免费软件。它按照 BSD 许可证的条款发布。有关更多信息,请参阅 LICENSE