PHP Library that implements several messaging patterns for RabbitMQ

Related tags

Queue Thumper
Overview

Thumper

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Thumper is a PHP library that aims to abstract several messaging patterns that can be implemented over RabbitMQ.

Inside the examples folder you can see how to implement RPC, parallel processing, simple queue servers and pub/sub.

Install

Via Composer

$ composer require php-amqplib/thumper

About the Examples

Each example has a README.md file that shows how to execute it. All the examples expect that RabbitMQ is running. They have been tested using RabbitMQ 2.1.1

For example, to publish message to RabbitMQ is as simple as this:

	$producer = new Thumper\Producer($connection);
	$producer->setExchangeOptions(array('name' => 'hello-exchange', 'type' => 'direct'));
	$producer->publish($argv[1]);

And then to consume them on the other side of the wire:

	$myConsumer = function($msg)
	{
	  echo $msg, "\n";
	};

	$consumer = new Thumper\Consumer($connection);
	$consumer->setExchangeOptions(array('name' => 'hello-exchange', 'type' => 'direct'));
	$consumer->setQueueOptions(array('name' => 'hello-queue'));
	$consumer->setCallback($myConsumer); //myConsumer could be any valid PHP callback
	$consumer->consume(5); //5 is the number of messages to consume.

Queue Server

This example illustrates how to create a producer that will publish jobs into a queue. Those jobs will be processed later by a consumer –or several of them–.

RPC

This example illustrates how to do RPC over RabbitMQ. We have a RPC Client that will send request to a server that returns the number of characters in the provided strings. The server code is inside the parallel_processing folder.

Parallel Processing

This example is based on the RPC one. In this case it shows how to achieve parallel execution with PHP. Let's say that you have to execute two expensive tasks. One takes 5 seconds and the other 10. Instead of waiting 15 seconds, we can send the requests in parallel and then wait for the replies which should take 10 seconds now –the time of the slowest task–.

Topic

In this case we can see how to achieve publish/subscribe with RabbitMQ. The example is about logging. We can log with several levels and subjects and then have consumers that listen to different log levels act accordingly.

Anonymous Consumers

Also inside the topic folder there's an anonymous consumer example. The idea here is for those situations when you need to hook up a queue to some exchange to "spy" what's going on, but when you quit your program you want that the queue is automatically deleted. We can achieve this using an unnamed queue.

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Disclaimer

This code is experimental. The idea is to show how easy is to implement such patterns with RabbitMQ and AMQP.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments
  • Find a new maintainer for the project

    Find a new maintainer for the project

    As you might know, I'm leaving the company that makes RabbitMQ https://groups.google.com/forum/#!topic/rabbitmq-users/-byffkRnI2w, so I will have even less time to take care of this project. Therefore I'm opening this issue so the community helps with finding a new maintainer(s) for the project.

    While I would like to have a stronger say on who should take care of the project, I would ask contributors and users to propose who you think would be a great candidate. Please comment on this issue and help find that person.

    Besides from knowing PHP, you must be very familiar with at least these concepts: http://www.rabbitmq.com/tutorials/amqp-concepts.html

    opened by videlalvaro 7
  • Add ConnectionRegistry to handle multiple connections easier

    Add ConnectionRegistry to handle multiple connections easier

    I try to stay KISS but feel free to comment the PR, I will update it.

    We plan to use Thumper for RabbitMq stuff in our next project.

    So you will have to deal with many PRs in the next days ;)

    opened by tyx 5
  • getChannel for BaseAmqp

    getChannel for BaseAmqp

    and another suggestion. The channel used is created in the BaseAmqp Class, but there is no way of getting it. Sure you could maybe do something like end($connection->channels), but that seems like a nasty solution and might even get you in trouble. Getting the current channel is necessary since the spawned channels are only closed on disconnect. If you have a long running process they will keep spamming and stay on the server without consumers.

    opened by hefekranz 2
  • heartbeat support

    heartbeat support

    Hi, I'm working on idled connexions that are caused by dead docker containers not interrupting rabbitmq connexions. I've read about the AMQP 0.9.1 spec and the heartbeat support, but haven't found any parameters available from thumper. Any plan to add/support heartbeat? Regards, Chris

    opened by cnaslain 1
  • Update thumper tag version

    Update thumper tag version

    Can you please add new tag version into thumper repository, I use you thumper lib in my QueueCenter lib and I already use ConnectionRegistry, but this class can not be found on any version tag

    opened by temafey 1
  • Remove destruct BaseAmqp

    Remove destruct BaseAmqp

    Close connection is already managed in destruct method of AMQPConnection class

    If we keep this destruct, it will be called first and will close connection. Then AMQPConnection destruct method will be called, and if close_on_destruct property is true, will try to close again... and we will get an exception.

    Am I wrong ? Should we not let Connection manage closing itself ?

    opened by tyx 1
  • Fixes for full CodeSniffer PSR-2 compliance

    Fixes for full CodeSniffer PSR-2 compliance

    • Updated docblock headers in lib to enhance compliance with phpdocumentor
    • Updated all spacing to match PSR-2 4 space indentation
    • Multi-line statements sorted out for compliance
    • Namespaces and use statements now compliant with newlines
    • Strings that don't require variable interpretation changed from double quote to single quote.
    • Added pedantic '' before use statements just to make it obvious it's from the root namespace.

    Think that's it.

    opened by shrikeh 1
  • Allow callback to reject (or nack) a message

    Allow callback to reject (or nack) a message

    The ack message is actually sent by the Consumer class right after call_user_func so there is no proper way for a callback to reject or nack the message expect throw an ugly exception.

    Solution can be to pass the $msg->delivery_info to the callback action and:

    • let it do the ack / nack / reject
    • do an ack call in Consumer if the callback hasn't send anything.
    opened by bastnic 1
  • Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase

    Use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase

    I use the PHPUnit\Framework\TestCase notation instead of PHPUnit_Framework_TestCase while extending our TestCases. This will help us migrate to PHPUnit 6, that no longer support snake case class names.

    opened by carusogabriel 0
  • update deps and bump version to 0.3.3 please

    update deps and bump version to 0.3.3 please

    please do this to update dependencies. now it says this:

    Your requirements could not be resolved to an installable set of packages.
    
      Problem 1
        - videlalvaro/thumper v0.3.2 requires videlalvaro/php-amqplib ~2.1.0 -> no matching package found.
        - videlalvaro/thumper v0.3.2 requires videlalvaro/php-amqplib ~2.1.0 -> no matching package found.
        - videlalvaro/thumper v0.3.2 requires videlalvaro/php-amqplib ~2.1.0 -> no matching package found.
        - Installation request for videlalvaro/thumper 0.3.2 -> satisfiable by videlalvaro/thumper[v0.3.2].
    
    Potential causes:
     - A typo in the package name
     - The package is not available in a stable-enough version according to your minimum-stability setting
       see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.
    
    Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.
    
    opened by tamtamchik 0
  • how to add params for this method

    how to add params for this method

    https://github.com/php-amqplib/Thumper/blob/71de0d0722ea6f6cd37361a9785f6e51b296136e/lib/Thumper/Consumer.php#L64

    I want to set $timeout for wait method, how to ?

    opened by runphp 1
  • suffixes for queues and exchanges

    suffixes for queues and exchanges

    This is not really an issue, but more a proposal: By default all queues and exchanges are suffixed with "-queue" and "-exchange". That can be a real problem, since the library dictates the naming of the interface, if you have an environment with predefined exchanges from other or former services, you can't hook in there using Thumper. I understand that this is a breaking change for people who adopted this behavior, but maybe you consider it for a future release.

    opened by hefekranz 0
  • Option to create queue in Producer

    Option to create queue in Producer

    When I create a Producer only the exchange gets created, no queue. If there is no consumer assigned to the exchange, messages will get lost. Is there an option to create the queue in the Producer and also in the Consumer, so it does not matter which got created first?

    opened by janwalther 1
  • Handle failures and retries?

    Handle failures and retries?

    I can't see a way in this library to reject a message in the callback upon some error condition so that RabbitMQ will retry the message.

    Am I missing something, or should I be using php-amqplib instead?

    opened by ebeyrent 6
Owner
php-amqplib
PHP Open-Source AMQP Packages
php-amqplib
The most widely used PHP client for RabbitMQ

php-amqplib This library is a pure PHP implementation of the AMQP 0-9-1 protocol. It's been tested against RabbitMQ. The library was used for the PHP

php-amqplib 4.2k Jan 6, 2023
RabbitMQ driver for ThinkPHP6 Queue.

RabbitMQ driver for ThinkPHP6 Queue.

null 2 Sep 14, 2022
RabbitMQ driver for Laravel Queue. Supports Laravel Horizon.

RabbitMQ Queue driver for Laravel Support Policy Only the latest version will get new features. Bug fixes will be provided using the following scheme:

Vladimir Yuldashev 1.6k Dec 31, 2022
Bernard is a multi-backend PHP library for creating background jobs for later processing.

Bernard makes it super easy and enjoyable to do background processing in PHP. It does this by utilizing queues and long running processes. It supports

Bernard 1.2k Jan 2, 2023
PHP client for beanstalkd queue

Pheanstalk Next (5) The master branch will be a WIP branch for v5 of this library until it is released. If any patches are needed in v4 they should be

null 1.9k Dec 21, 2022
PHP bindings for Tarantool Queue.

Tarantool Queue Tarantool is a NoSQL database running in a Lua application server. It integrates Lua modules, called LuaRocks. This package provides P

Tarantool PHP 62 Sep 28, 2022
Message Queue, Job Queue, Broadcasting, WebSockets packages for PHP, Symfony, Laravel, Magento. DEVELOPMENT REPOSITORY - provided by Forma-Pro

Supporting Enqueue Enqueue is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and

Enqueue 2.1k Dec 22, 2022
PHP client for beanstalkd queue

Pheanstalk Pheanstalk is a pure PHP 7.1+ client for the beanstalkd workqueue. It has been actively developed, and used in production by many, since la

null 1.9k Dec 21, 2022
PHP-Queue: A unified front-end for different queuing backends. Includes a REST server, CLI interface and daemon runners.

A unified front-end for different queuing backends. Includes a REST server, CLI interface and daemon runners. Why PHP-Queue? Implementing a

CoderKungfu 646 Dec 30, 2022
PHP Library that implements several messaging patterns for RabbitMQ

Thumper Thumper is a PHP library that aims to abstract several messaging patterns that can be implemented over RabbitMQ. Inside the examples folder yo

php-amqplib 276 Nov 20, 2022
sample code for several design patterns in PHP 8

DesignPatternsPHP Read the Docs of DesignPatternsPHP or Download as PDF/Epub This is a collection of known design patterns and some sample codes on ho

null 21k Jan 1, 2023
Sample code for several design patterns in PHP 8

DesignPatternsPHP Read the Docs of DesignPatternsPHP or Download as PDF/Epub This is a collection of known design patterns and some sample codes on ho

null 21k Jan 5, 2023
PHP Client and Router Library for Autobahn and WAMP (Web Application Messaging Protocol) for Real-Time Application Messaging

Thruway is an open source client and router implementation of WAMP (Web Application Messaging Protocol), for PHP. Thruway uses an event-driven, non-blocking I/O model (reactphp), perfect for modern real-time applications.

Voryx 662 Jan 3, 2023
Performant pure-PHP AMQP (RabbitMQ) sync/async (ReactPHP) library

BunnyPHP Performant pure-PHP AMQP (RabbitMQ) sync/async (ReactPHP) library Requirements BunnyPHP requires PHP 7.1 and newer. Installation Add as Compo

Jakub Kulhan 641 Dec 29, 2022
Flexihash is a small PHP library which implements consistent hashing.

Flexihash Flexihash is a small PHP library which implements consistent hashing, which is most useful in distributed caching. It requires PHP5 and uses

Paul Annesley 364 Oct 18, 2022
This library implements a fuzzer for PHP, which can be used to find bugs in libraries

PHP Fuzzer This library implements a fuzzer for PHP, which can be used to find bugs in libraries (particularly parsing libraries) by feeding them "ran

Nikita Popov 341 Dec 25, 2022
PHP Email address validator - A library for validating emails against several RFC.

EmailValidator A library for validating emails against several RFC. Supported RFCs This library aims to support RFCs: 5321, 5322, 6530, 6531, 6532, 10

Eduardo Gulias Davis 10.7k Jun 13, 2022
[virion] It Implements Simple Using Form Library System

SimpleForm [virion] It Implements Simple Using Form Library System How To Use First, declare the use statement. use AidenKR\SimpleForm\SimpleForm; use

Aiden 2 Sep 18, 2021
A simple cache library. Implements different adapters that you can use and change easily by a manager or similar.

Desarolla2 Cache A simple cache library, implementing the PSR-16 standard using immutable objects. Caching is typically used throughout an applicatito

Daniel González 129 Nov 20, 2022
A simple cache library. Implements different adapters that you can use and change easily by a manager or similar.

Desarolla2 Cache A simple cache library, implementing the PSR-16 standard using immutable objects. Caching is typically used throughout an applicatito

Daniel González 129 Nov 20, 2022