Download the PHP package toalett/react-amqp-stream without Composer

On this page you can find all versions of the php package toalett/react-amqp-stream. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package react-amqp-stream

🚽 Toalett

Welcome to Toalett, a humble initiative. Toalett is the Norwegian word for toilet 💩.

What is toalett/react-amqp-stream?

This is a libary that allows you to interact with an AMQP message queue as if it were a readable stream in ReactPHP. It's very lightweight - its only dependencies are toalett/react-stream-adapter and php-amqplib/php-amqplib.

The class AMQPSource implements the Toalett\React\Stream\Source interface from toalett/react-stream-adapter. It needs an instance of PhpAmqpLib\Channel\AMQPChannel and the name of the queue to read from. You may provide additional options for the call to AMQPChannel::basic_consume() by passing in an Options object as the third parameter of the constructor.

The Toalett\React\Stream\StreamAdapter wraps a Source and makes it approachable as a readable stream in an event loop.

Installation

It is available on Packagist:

Motivation

Note: this motivation is the same as given in toalett/react-stream-adapter.

I was working on a project that required an application to respond to AMQP messages in a non-blocking way. The application made use of an event loop. Initially I used a periodic timer with a callback, but as the application grew this became a cluttered mess. It slowly started to feel more natural to treat the message queue as a stream. This makes sense if you think about it:

In computer science, a stream is a sequence of data elements made available over time. A stream can be thought of as items on a conveyor belt being processed one at a time rather than in large batches.

Stream (computing) on Wikipedia

This definition suits a message queue.

In the project I mentioned earlier, I use this library to poll an AMQP queue every 10 seconds. This keeps my load low and allows me to do other things in the meantime. This abstraction turned out really useful, so I thought that others might enjoy it too.

How do I use this?

The library tries to stay out of your way as much as possible. Going from an AMQP connection to a readable stream only takes a few lines of code! 😀

  1. Create a connection to an AMQP host with PhpAmqpLib, and grab a channel.
  2. Pass the channel instance and the name of the queue to consume, optionally with an instance of AMQPSource.
  3. Create an event loop using the React\EventLoop\Factory.
  4. Create a StreamAdapter, and pass the AMQPSource and the event loop to the constructor.
  5. Interact with the adapter as if it were any other ReadableInputStream.

Let us see this in action with two examples.

As you can see, it takes only 2 SLOC to go from an AMQP connection or channel to a readable stream.

The Options class provides a way to pass arguments to the call to AMQPChannel::basic_consume. Once you passed the AMQPSource, you lose the ability to change them; the Options instance is cloned to prevent unexpected behaviour.

If you don't provide a consumer tag, the server will assign one. You can retrieve this consumer tag from an AMQPSource with getConsumerTag().

Check out the examples folder for some simple implementations. They are not much different than the ones given in this readme. Feel free to play around with them.

Note: There are some concessions with regards to latency due to the fact that the stream adapter library uses polling under the hood. Please refer to toalett/react-stream-adapter for more information about this subject.

Questions

Q: How do I handle stream errors?
A: The RuntimeException that is passed to the on('error', ...) callback contains the exception that was actually thrown by the Source. Calling getPrevious() on the RuntimeException gives you the original exception.

Q: Where are the tests?
A: Tests might be added later. Feel free to create an issue if the lack of tests bothers you!


All versions of react-amqp-stream with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4
toalett/react-stream-adapter Version ^1.0
php-amqplib/php-amqplib Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package toalett/react-amqp-stream contains the following files

Loading the files please wait ....