PHP Library that implements several messaging patterns for RabbitMQ

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
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
[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
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 3, 2023
A PHP implementation of RabbitMQ Client for webman plugin.

workbunny/webman-rabbitmq ?? A PHP implementation of RabbitMQ Client for webman plugin. ?? A PHP implementation of RabbitMQ Client for webman plugin 常

workbunny 15 Dec 15, 2022
InventoryUI - the PocketMine virion that implements the dummy inventory

InventoryUI This is the PocketMine virion that implements the dummy inventory. Differences from previous APIs Chests and other blocks are not placed.

tedo0627 10 Nov 16, 2022
This package implements 0-1 Knapsack Problem algorithm i.e. allows to find the best way to fill a knapsack of a specified volume with items of a certain volume and value.

This package implements "0-1 Knapsack Problem" algorithm i.e. allows to find the best way to fill a knapsack of a specified volume with items of a certain volume and value.

Alexander Makarov 9 Sep 8, 2022
Simple async lowlevel ICMP (ping) messaging library built on top of React PHP

clue/icmp-react Simple async lowlevel ICMP (ping) messaging library built on top of react Usage Once clue/icmp-react is installed, you can run any of

Christian Lück 13 Jun 10, 2022
Xenon\LaravelBDSms is a sms gateway package for sending text message to Bangladeshi mobile numbers using several gateways like sslcommerz, greenweb, dianahost,metronet in Laravel framework

Xenon\LaravelBDSms is a sms gateway package for sending text message to Bangladeshi mobile numbers using several gateways for Laravel. You should use

Ariful Islam 95 Jan 3, 2023
Live chat with several people.

chat What can you do on this application? you can create an account you can talk live with several people you can edit any information on your account

Narcis Lazar 8 Nov 10, 2022
🐋 This project aims to broaden knowledge of system administration by using Docker: virtualizing several Docker images, creating them in a new personal virtual machine.

?? This project aims to broaden knowledge of system administration by using Docker: virtualizing several Docker images, creating them in a new personal virtual machine.

Anton Kliek 1 Jan 26, 2022
Detection of design patterns in PHP code

Pattern Detector for PHP Detects design pattern in your code

Jean-François Lépine 105 Aug 23, 2022
Examples of some common design patterns implemented in php

What is a Design Pattern? Design patterns are typical solutions to common problems in software design. Each pattern is like a blueprint that you can c

Bakhtiyor Bahritidinov 4 Feb 11, 2022
Messaging solutions for PHP - It contains advanced features build on top of a transport component

It contains advanced features build on top of a transport component. Client component kind of plug and play things or consumption component that simplify message processing a lot. Read more about it in documentation.

Enqueue 175 Jan 3, 2023
The easiest way to match data structures like JSON/PlainText/XML against readable patterns. Sandbox:

PHP Matcher Library created for testing all kinds of JSON/XML/TXT/Scalar values against patterns. API: PHPMatcher::match($value = '{"foo": "bar"}', $p

Coduo 774 Dec 31, 2022
CDK patterns for serverless container with AWS Fargate

cdk-fargate-patterns CDK patterns for serverless container with AWS Fargate DualAlbFargateService Inspired by Vijay Menon from the AWS blog post intro

Pahud Hsieh 48 Sep 1, 2021
Repo do vídeo do youtube de Design Patterns - Decorator

DesignPatternsPHP-Decorator Repo do vídeo do Youtube de Design Patterns - Decorator Link do vídeo Decorator em PHP 8 Imagem de exemplo Link do cadastr

Leonardo Tumadjian 10 Aug 18, 2022
Learning design patterns by implementing them in various programming languages.

design-patterns Learning design patterns by implementing them in various programming languages. Creational design patterns Creational design patterns

Paweł Tryfon 1 Dec 13, 2021
Starless Sky is a network protocol for secure identities, providing the use of assymetric identities, public information, end-to-end messaging and smart contracts

Descentralized network protocol providing smart identity over an secure layer. What is the Starless Sky Protocol? Starless Sky is a network protocol f

Starless Sky Protocol 3 Jun 19, 2022
A fully-managed real-time messaging service that allows you to send and receive messages between independent applications.

A fully-managed real-time messaging service that allows you to send and receive messages between independent applications.

Google APIs 58 Dec 23, 2022