coinvestor/laravel-batchsqs 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

coinvestor/laravel-batchsqs

Composer 安装命令:

composer require coinvestor/laravel-batchsqs

包简介

An alternative Amazon SQS queue driver for Laravel. Messages are sent in batches rather than one at a time, which may be more efficient if you have a lot of messages to send.

README 文档

README

SQS queue connector for Laravel which sends messages in batches.

Installation

To install:

composer require coinvestor/laravel-batchsqs

Then to publish config files:

artisan vendor:publish

(select the BatchSQSProvider option when prompted)

Usage

This package provides a queue connector called batch-sqs. Create a block inside connections as usual:

'connections' => [
        'batch-sqs' => [
            'driver'      => 'batch-sqs',
            'key'         => env('AWS_KEY', null),
            'secret'      => env('AWS_SECRET', null),
            'prefix'      => env('AWS_PREFIX', null),
            'queue'       => env('AWS_QUEUE', null),
            'region'      => env('AWS_REGION', null),
            'batch_size'  => 7,
        ],
// [...]

You can use all of the usual Laravel SQS queue config options. In addition, you can set batch_size to define how many messages will be included in each batch (once the batch is full, the messages will be released to the queue).

When the queue object is destroyed (e.g. at the end of the request lifecycle, when Laravel is shutting down), messages which are still waiting to be sent to the queue will be sent, even if the batch size limit has not been reached.

Modifying messages before release

When a batch of messages is released to the queue, CoInvestor\BatchSQS\Queues\Events\BatchMessageReleasingEvent is dispatched. To modify each message before it reaches the queue, simply define a listener which will inspect the message and then return an array which will be merged with the message before it is released:

<?php
use \CoInvestor\BatchSQS\Queues\Events\BatchMessageReleasingEvent;
class BatchMessageReleasingEventListener
{
    public function handle(BatchMessageReleasingEvent $event)
    {
        $return = [];

        // If the message is 'foo' it should be changed to 'foobar'
        if ($event->message['MessageBody'] == 'foo') {
            $return['MessageBody'] = 'foobar';
        }
        // If the queue name ends in .norbert, the message should have a message group id consisting of 128 '1's
        if (preg_match('/.*\.norbert/', $event->queue)) {
            $return['MessageGroupId'] = str_repeat("1", 128);
        }

        return $return;
    }
}

Flushing the queue

You may wish to send batches to your queues before they are full, or discard them entirely. Here's how:

use Illuminate\Support\Facades\Queue;

// Send all message batches to their respective queues
Queue::flush();

// Discard all message batches
Queue::flush(true);

统计信息

  • 总下载量: 4.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 5
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-08-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固