beyerz/aws-queue-bundle
Composer 安装命令:
composer require beyerz/aws-queue-bundle
包简介
Symfony bundle to connect AWS sns and sqs to create offline queue processing
关键字:
README 文档
README
About
AWS Queue Bundle for Symfony2
The purpose of this bundle is to provide an easy integration between symfony services and AWS services. Queues are defined by Producers and Consumers
By using this bundle, together with aws bundle, the Consumer and Producer services that you define will automatically setup the AWS services on demand. This eases the requirement of setting up your queue and notification services through the AWS platform.
Installation
Composer (Recommended)
composer require beyerz/aws-queue-bundle
Application Kernel
Add BeyerzAWSQueueBundle to the registerBundles() method of your application kernel:
public function registerBundles() { return array( new Beyerz\AWSQueueBundle\BeyerzAWSQueueBundle(), ); }
Usage
Config
config.yml
beyerz_aws_queue: region: #Your AWS region that you want to use account: #Your AWS Account ID channel_prefix: "%kernel.environment%" #used to separate dev/stage/prod (mainly to make development eaiser) run_local: false #This option should allow you to run remotely using aws, or locally using no-queue or gearman
Important config note:
Due to the way that Aws has defined the working tree, the aws-queue-bundle cannot automatically append your configs.
The result of this is that you will need to define the aws configuration yourself.
Documentation
Creating a Producer
Creating a producer that can be used in your system is really simple, here is some sample code to get you started You can also look at the demo folder in this bundle AcmeBundle/Producers/MyAwesomeProducer.php
<?php namespace Acme\AcmeBundle\Producers; use Beyerz\AWSQueueBundle\Interfaces\ProducerInterface; use Beyerz\AWSQueueBundle\Producer\ProducerTrait; class MyAwesomeProducer implements ProducerInterface { use ProducerTrait; public function publish($message) { $this->producer->publish($message); } }
Producers require some setup which is handled by this bundle and you dont really have to worry too much about it. We have provided both and interface and trait for producers and as long you have included them, the setup should go smoothly.
Next, we need to define the producer as a service so that we can tag it and make the AwsQueueBundle aware that it exists :)
AcmeBundle/Resources/config/services.yml
parameters: acme.my_awesome_producer.class: Acme\AcmeBundle\Producers\MyAwesomeProducer services: acme.my_awesome_producer: class: "%acme.my_awesome_producer.class%" tags: - {name: "beyerz_aws_queue.producer", channel: "awesome_producer"}
You can now access your producer as you normally would through symfony container
<?php $myAwesomeProducer = $this->container->get('acme.my_awesome_producer'); $myMessage = "My Awesome Message"; $myAwesomeProducer->publish($message);
After running this producer, you can go to SNS service in your amazon account and see a new topic has been created for you. You will not yet have queues in your SQS as we have not yet created any consumers
Creating a Consumer
Consumer are a little more complex than producers, but the basic concept to understand is that your consumer class receives the message from the queue for you to process.
AcmeBundle/Consumers/MyAwesomeConsumer.php
<?php namespace Acme\AcmeBundle\Consumers; use Beyerz\AWSQueueBundle\Interfaces\ConsumerInterface; class MyAwesomeConsumer implements ConsumerInterface { public function consume($message) { //do something awesome with your message } }
Consumers require some setup which is handled by this bundle and you dont really have to worry too much about it. We have provided both an interface and as long you have implemented it, the setup should go smoothly. Your consumer class gets "wrapped" in a special consumer service. This wrapper connects to the queue and passes the message to your consume function. This wrapper loads your consumer using service container, this means that you can create your service as you normally would, so you can even add dependecies to a constructor!
Next, we need to define the consumer as a service so that we can tag it and make the AwsQueueBundle aware that it exists :) There are two tags that we are going to use. The first tag tells the bundle that this is a consumer and the defines the name of the SQS queue using the channel key The second tag tells the bundle which producer this consumer wants to subscribe to. If you want to subscribe this queue to more than one producer, just duplicate the tag and define the producer name accordingly
AcmeBundle/Resources/config/services.yml
parameters: acme.my_awesome_consumer.class: Acme\AcmeBundle\Consumers\MyAwesomeConsumer services: acme.my_awesome_consumer: class: "%acme.my_awesome_consumer.class%" tags: - {name: "beyerz_aws_queue.consumer", channel: "awesome_consumer"} - {name: "beyerz_aws_queue.subscriber", producer: "awesome_producer"}
Now you can run your producer using cli
php app/console beyerz:consumer awesome_consumer
Your consumer will keep running unless you specify a max message limit or something crashes. Its probably best to start your consumers using a task management system such as supervisor or even jenkins. If you have processes that you prefer to run at specific times and not continuosly you can also use crontab
beyerz/aws-queue-bundle 适用场景与选型建议
beyerz/aws-queue-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.1k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 07 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「Symfony2」 「aws」 「sqs」 「amazon web services」 「SNS」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 beyerz/aws-queue-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 beyerz/aws-queue-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 beyerz/aws-queue-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
This package includes a script and fail2ban configuration that allows you to use fail2ban when utilizing AWS elastic load balancer (ELB) and an apache webserver.
Elastic Driver for Laravel Scout
simple api library.
A replica of the AWS Elastic Beanstalk worker SQS daemon (sqsd) in PHP
Bundle Symfony DaplosBundle
统计信息
- 总下载量: 1.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2018-07-29