承接 nsmithuk/dynamo-queue-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

nsmithuk/dynamo-queue-php

Composer 安装命令:

composer require nsmithuk/dynamo-queue-php

包简介

README 文档

README

Overview

DynamoQueue is a DynamoDB backed queue library. The PHP version provides both queueing and worker components.

DynamoQueue features:

  • Each job will be received by one worker, once, and only once.
  • The status of jobs in the queue can be tracked by their job ID.
  • Jobs will be processed in the order* in which they are added (*see Job Processing Order).
  • All the scalability benefits of Amazon’s DynamoDB.
  • Jobs can be up to 400 KB in size (see Messages).

Installation

Simplest is to add the following to composer.json:

{
    "require": {
        "nsmithuk/dynamo-queue-php": "^1.0"
    }
}

And then run:

php composer.phar install

Initial Setup

The first thing needed is to create a suitable table in DynamoDB. This can be done directly form the DynamoQueue Worker client.

bin/dynamo-queue --key <key> --secret <secret> --region <region> --table <name> --create

Where

  • key is your AWS access key
  • secret is your AWS access secret
  • region is the AWS region you want the table to be in. e.g. eu-west-1, us-east-1, etc.
  • table the name of the table to create

Alternatively to specifying the key and secret here, they can be specified as environment variables, or set via IAM roles for Amazon EC2 instances. More details here.

A full list of supported regions can be found here: http://docs.aws.amazon.com/general/latest/gr/rande.html#ddb_region

Note - This command only provisions 1 read and 1 write unit each for the Table and the Global Secondary Index. This is fine for testing but should be changed to a more suitable value for production.

Starting the worker

Once a table has been created a worker can be started using the command

bin/dynamo-queue --key <key> --secret <secret> --region <region> --table <name>

Where

  • key is your AWS access key
  • secret is your AWS access secret
  • region is the AWS region in which you created the table.
  • table the name of the table you created

Alternatively to specifying the key and secret here, they can be specified as environment variables, or set via IAM roles for Amazon EC2 instances. More details here.

Adding jobs to the queue

Assuming you've installed DynamoQueue via Composer, the DynamoQueue client will be available via the autoloader.

// First create an instance of the DynamoDbClient from Amazon’s SDK
$dynamoDb = new \Aws\DynamoDb\DynamoDbClient([
    'version' => '2012-08-10',
    'region' => '<region>',
    'credentials' => [
        'key'    => '<key>',
        'secret' => '<secret>',
    ]
]);

// Create an instance of the DynamoQueue client
$queue = new \DynamoQueue\Queue\Client( $dynamoDb, [ 'table_name' => '<table name>' ] );

You can then add jobs to the queue using

$queue->enqueue( $processor, $message )

Where

  • processor is the Processor the Worker will use to execute the job. By default in PHP, this should be a full classname (including namespace) of a class that implements the ProcessorInterface, that is accessible via the autoloader within the Worker.
  • message is a string containing the message/instruction to be passed to the Worker. For rich data we recommend this is a JSON string. Binary data is also supported for if you wish to compress and/or encrypt the data.

For example:

$jobId = $queue->enqueue( 'DynamoQueueTests\Processors\EchoMessage', "Test Message" );

Alternatively you can specify your own unique jobId if you wish:

$queue->enqueue( 'DynamoQueueTests\Processors\EchoMessage', "Test Message", "id-1" );

Messages

As per DynamoDB limits, each individual job - including all metadata - cannot be greater than 400 KB.

Realistically however as AWS charge basically on a per KB basis for writes, it’s strongly recommended you make messages as small as possible; ideally less than 1 KB.

This can be aided by:

  • Compressing messages before adding them to the queue; or
  • Storing the main message elsewhere - in S3 or a database for example - then just passing a reference to the message through the queue.

Job Processing Order

To aid scalability DynamoQueue supports distributing jobs across partitions. In DynamoQueue’s default configuration of a single partition, jobs are processed in exactly the order they were added to the queue. When more than one partition is used jobs are processed in approximately the order they were added. The greater the number of partitions used, the lower the correlation between when they were added and when they are processed.

nsmithuk/dynamo-queue-php 适用场景与选型建议

nsmithuk/dynamo-queue-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 258 次下载、GitHub Stars 达 2, 最近一次更新时间为 2015 年 08 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 nsmithuk/dynamo-queue-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nsmithuk/dynamo-queue-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 nsmithuk/dynamo-queue-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-08-07