2017 © Pedro Peláez
 

library butter-amqplib

Butter AMQP library for PHP, written purely in PHP

image

skolodyazhnyy/butter-amqplib

Butter AMQP library for PHP, written purely in PHP

  • Thursday, June 14, 2018
  • by skolodyazhnyy
  • Repository
  • 2 Watchers
  • 3 Stars
  • 61 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Butter AMQP

Build Status Scrutinizer Code Quality Code Coverage, (*1)

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., (*2)

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

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., (*4)

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

$ 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., (*6)

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., (*7)

Every code snippet below extends previous one., (*8)

Connecting to the server

Establish connection to the server and open a channel., (*9)

use ButterAMQP\ConnectionBuilder;

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

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

Read more, (*10)

Define topology

Declare exchanges and queues., (*11)

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, (*12)

Publishing messages

Publish a message to newly declared exchange and it will be delivered to the queue., (*13)

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, (*14)

Consuming messages

Receive your message and acknowledge its delivery., (*15)

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, (*16)

Close connection

Properly closing connection to the server will guarantee all temporary queues will be deleted and resources released., (*17)

You don't need to close channels, just connection will be enough., (*18)

$connection->close();

Known issues

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

The Versions

14/06 2018

dev-master

9999999-dev https://github.com/skolodyazhnyy/butter-amqplib

Butter AMQP library for PHP, written purely in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Kolodyazhnyy

amqp amqplib

14/06 2018

dev-add-license-1

dev-add-license-1 https://github.com/skolodyazhnyy/butter-amqplib

Butter AMQP library for PHP, written purely in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Kolodyazhnyy

amqp amqplib

21/10 2016

dev-test

dev-test https://github.com/skolodyazhnyy/butter-amqplib

Butter AMQP library for PHP, written purely in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Kolodyazhnyy

amqp amqplib

17/09 2016

0.1.0

0.1.0.0 https://github.com/skolodyazhnyy/butter-amqplib

Butter AMQP library for PHP, written purely in PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

by Sergey Kolodyazhnyy

amqp amqplib