SQS 实现作为 spryker/queue 的适配器

1.0.0 2023-08-01 15:11 UTC

This package is auto-updated.

Last update: 2024-09-09 12:48:04 UTC


README

SQS 实现作为 spryker/queue 的适配器

安装包

composer req valantic-spryker-eco/sqs

更新共享配置

config/Shared/config_default.php

$config[KernelConstants::CORE_NAMESPACES] = [
    ...
    'ValanticSpryker',
];

更新您的共享配置以用于 SQS(ElasticMQ 示例)

$config[SqsConstants::SQS_BASE_URL] = 'http://elasticmq:9324';
$config[SqsConstants::SQS_QUEUE_PATH_PREFIX] = 'queue/';

更新您的 QueueConfig

\Pyz\Zed\Queue\QueueConfig

...

/**
 * @var string
 */
public const AWS_SQS = 'aws-sqs';

...

/**
 * @return array
 */
protected function getMessageCheckOptions(): array
{
    return [
        QueueConstants::QUEUE_WORKER_MESSAGE_CHECK_OPTION => [
        ...
        static::AWS_SQS => $this->getAwsSqsQueueMessageCheckOptions(),
    ];
}

...

/**
 * @return \Generated\Shared\Transfer\AwsSqsConsumerOptionTransfer
 */
protected function getAwsSqsQueueMessageCheckOptions(): AwsSqsConsumerOptionTransfer
{
    $queueOptionTransfer = new AwsSqsConsumerOptionTransfer();
    $queueOptionTransfer->setCheckMessageCount(true);

    return $queueOptionTransfer;
}

...

更新您的 ConsoleDependencyProvider

\Pyz\Zed\Console\ConsoleDependencyProvider

/**
 * @param \Spryker\Zed\Kernel\Container $container
 * 
 * @return \Symfony\Component\Console\Command\Command[]
 */
protected function getConsoleCommands(Container $container): array
{
    $commands = [
        ...
        new SqsCreateQueuesConsole(),
        new SqsPurgeAllQueuesConsole(),
        new SqsRemoveQueuesConsole(),
    ];

在许多情况下,当您在 RabbitMq 旁边操作 SQS 时,将 Queue 模块扩展以将 RabbitMq 工作进程与 SQS 工作进程分开也是有意义的。为了实现这一点,您应该扩展 QueueDependencyProviderQueueBusinessFactory 来独立创建 RabbitMq 和 SQS 的 TaskWorker