puzzle/amqp
Composer 安装命令:
composer require puzzle/amqp
包简介
AMQP implementation based on PECL extension
关键字:
README 文档
README
PHP 5.6 & 7.x users, please use < 5.x versions.
QA
| Service | Result |
|---|---|
| CI (PHP 8.3, 8.4, 8.5) | |
| Packagist |
Configuration
# amqp.yml broker: host: myRabbit port: 5672 login: guest password: guest vhost: / global: disallowSilentDropping: false # app.yml id: myApp
Usage
Sending a message
<?php require '../vendor/autoload.php'; use Puzzle\Configuration\Memory; use Puzzle\AMQP\Clients\Pecl; use Puzzle\AMQP\Messages\Message; $configuration = new Memory(array( 'amqp/broker/host' => 'myRabbit', 'amqp/broker/login' => 'guest', 'amqp/broker/password' => 'guest', 'amqp/broker/vhost' => '/', 'app/id' => 'myApp', )); $client = new Pecl($configuration); $message = new Message('my.routing.key'); $message->setJson([ 'key' => 'value', 'key2' => 'value2', ]); $client->publish('myExchange', $message);
Consuming a message
Worker declaration :
<?php use Puzzle\AMQP\Consumers; use Puzzle\AMQP\Clients; use Puzzle\AMQP\Workers\ProcessorInterfaceAdapter; use Puzzle\Configuration\Memory; $configuration = new Memory(array( 'amqp/broker/host' => 'rabbitmq', 'amqp/broker/login' => 'guest', 'amqp/broker/password' => 'guest', 'amqp/broker/vhost' => '/', 'app/id' => 'myApp', )); $consumer = new Consumers\Simple(); $worker = new ExampleWorker(); $consumer->consume( new ProcessorInterfaceAdapter($worker), new Clients\Pecl($configuration), 'queue.name' );
Worker example :
<?php use Psr\Log\LoggerAwareTrait; use Psr\Log\NullLogger; use Puzzle\AMQP\ReadableMessage; use Puzzle\AMQP\Workers\Worker; class ExampleWorker implements Worker { use LoggerAwareTrait; public function __construct() { $this->logger = new NullLogger(); } public function process(ReadableMessage $message): void { // your code here } }
BC Breaks changelog
5.x -> 8.x
- Since version 8.3 : version name follows minimal supported php version
- For version changelog : see Github's release description
4.x -> 5.x
- Drop support for php 5.6 & 7.x
- Worker now catch Throwable, not only Exceptions
- Consumer / Worker / WorkerContext signature change
3.x -> 4.x
- Chunk management introduced in 3.1 has been refactored and made easier : just use Streamed* bodies and same client as usual
2.x -> 3.x
- Message hooks has been removed
- Raw & Json implementations of WritableMessage has been replaced by Message + implementations of Body (Text, Json, Binary)
- Message interface has been renamed into MessageMetadata
- Some specific features removed from WorkerContext
- Getter for specific headers removed from MessageAdapter
- Message InMemory implementation (for unit testing purpose) has been changed
- MessageAdapter must not be directly constructed anymore, use MessageAdapterFactory instead
1.x -> 2.x
- Drop support for Silex 1.x (in favor of Silex 2.x)
puzzle/amqp 适用场景与选型建议
puzzle/amqp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 48.58k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「AMQP」 「asynchronous」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 puzzle/amqp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 puzzle/amqp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 puzzle/amqp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Queue
Asynchronous coroutines for PHP 7.
Work with RabbitMQ in Laravel.
PHP AMQP Binding Library
The Listener component of the RabbitEvents library.
The Publisher component of the RabbitEvents package.
统计信息
- 总下载量: 48.58k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-06