GithubHelp home page GithubHelp logo

thumper's Introduction

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.

thumper's People

Contributors

cgardner avatar foxwoods avatar ivaano avatar khepin avatar postalservice14 avatar rigosv avatar sasha-ch avatar shrikeh avatar tamtamchik avatar tyx avatar videlalvaro avatar yahuarkuntur avatar zircote avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

thumper's Issues

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?

PHP 8 support

composer.json limits PHP version to 7.x.
Any chance of supporting PHP 8.0 or even 8.1?

Add to packagist

Any plans to add this on packagist so it can be installed without adding a repository in the composer.json ?

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.

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.

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

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

Composer Tags

Could you do a forced update on packagist.org please? It doesn't recognize the two tags.

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

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.

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.