skolodyazhnyy/butter-amqplib 问题修复 & 功能扩展

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

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

skolodyazhnyy/butter-amqplib

Composer 安装命令:

composer require skolodyazhnyy/butter-amqplib

包简介

Butter AMQP library for PHP, written purely in PHP

关键字:

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage

Butter AMQP is a client library for AMQP protocol purely implemented in PHP. It has no dependencies on any PHP extension nor other PHP packages. It's very light-weight and lightning fast.

Butter AMQP supports all base AMQP features and RabbitMQ extensions, including: exchange to exchange bindings, publisher acknowledgments, negative acknowledgements and others.

Key features

  • Pure PHP implementation of AMQP protocol: no special requirements for PHP and easy upgrade using just composer
  • Easy to use functional API, it hides implementation details and reduce risk of making mistake
  • Code generator for frame encoding and decoding helps achieve high performance and low memory usage
  • Clean design makes it pleasure to work with AMQP, easy to tests and understand
  • Full support for AMQP protocol version 0.9.1 and RabbitMQ extensions

Installation

Easiest way to start using Butter AMQP library is to install it using composer. It has almost no dependencies and does not conflict with any other library.

Open a command console, enter your project directory and execute the following command to download the latest version of this library.

$ composer require skolodyazhnyy/butter-amqplib dev-master

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Usage

If you are new to AMQP, I suggest you have a look into RabbitMQ tutorial which explains all features of AMQP protocol in only 6 chapters tutorial! I have adopted it with code samples for Butter AMQP.

Every code snippet below extends previous one.

Connecting to the server

Establish connection to the server and open a channel.

use ButterAMQP\ConnectionBuilder;

$connection = ConnectionBuilder::make()
    ->create("//guest:guest@localhost/%2f");

$channel = $connection->channel(1);

Read more

Define topology

Declare exchanges and queues.

use ButterAMQP\ExchangeInterface as Exchange;
use ButterAMQP\QueueInterface as Queue;

$channel->exchange('butter')
    ->define(Exchange::TYPE_FANOUT, Exchange::FLAG_DURABLE);
    
$channel->queue('butter')
    ->define(Queue::FLAG_DURABLE | Queue::FLAG_EXCLUSIVE)
    ->bind('butter');

Read more

Publishing messages

Publish a message to newly declared exchange and it will be delivered to the queue.

use ButterAMQP\Message;

// Construct a message to be published
$message = new Message('hi there', ['content-type' => 'text/plain']);

// Publish message to default exchange, with routing key "text-messages".
$channel->publish($message, '', 'text-messages');

Read more

Consuming messages

Receive your message and acknowledge its delivery.

use ButterAMQP\Delivery;

// Declare consumer
$consumer = $channel->consume('text-messages', function(Delivery $delivery) {
    echo "Receive a message: " . $delivery->getBody() . PHP_EOL;
    
    // Acknowledge delivery
    $delivery->ack();
});

// Serve connection until consumer is cancelled
while($consumer->isActive()) {
    $connection->serve();
}

Read more

Close connection

Properly closing connection to the server will guarantee all temporary queues will be deleted and resources released.

You don't need to close channels, just connection will be enough.

$connection->close();

Known issues

  • Decimal type is not supported
  • Unsigned long long type is not supported

skolodyazhnyy/butter-amqplib 适用场景与选型建议

skolodyazhnyy/butter-amqplib 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 71 次下载、GitHub Stars 达 4, 最近一次更新时间为 2016 年 09 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「AMQP」 「AMQPLib」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 skolodyazhnyy/butter-amqplib 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-05