Download the PHP package tzmudz/rabbitmq_rpc without Composer

On this page you can find all versions of the php package tzmudz/rabbitmq_rpc. 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 rabbitmq_rpc

RabbitMQ RPC message

stable

This package makes ready to use implementation of RabbitMQ RPC tutorial published on: https://www.rabbitmq.com/tutorials/tutorial-six-php.html It implements both server side and client.

Thanks to this package you will be able to send a message to RabbtiMQ, then receive this message (on the server side) handle it and finally send the response to the client (Producer).

Unlike tutorial this package is set to save the queue and messages after RabbtiMQ server reboot.

Installation

Installation of the package by Composer:

Package uses an Environment Variables delivered by vlucas/phpdotenv package. You have to create an .env file in the root folder containing variables:

Thus if you are using e.g. Laravel all you have to do is to put this variables in your .env app file. Notice If your application doesn’t use .env files, don't forget to load them by executing the code:

You can find more information here: https://github.com/vlucas/phpdotenv

Usage

Package comes with two classes: Producer and Consumer.

Producer

The Producer class is responsible for delivering messages to RabbtiMQ. In your application create a new instance of Tzm\Rpc\Producer(). As a parameter you can set the queue name (by default the name is default):

Otherwise you can set the queue name by calling the setQueueName().

Finally you have to call the method call() with message as parameter:

Where $message is a string of data that should be send to the RabbtiMQ server. Actually RPC sends a message and waits for the response given from server. But, if you don't want to wait for server’s response you can use withoutWaiting():

Consumer

To process the queued message you need Consumer class. This class is abstract. You have to create a new class that inherits from Consumer abstract class. Then you have to implement several methods.

handleMessage()

This method is responsible for process the message. It accepts $message as a parameter e.g.

handleError()

Generally it's not necessary, but it handles the error. If the method handleMessage() thrown an error it will be passed to the handleError() method. So that you can handle the error however you want. e.g. in Laravel you can log the error message:

setResults()

After the message is handled RabbitMQ returns a response message. Initially it returns true. But if you want you can use setResult() method to set the data you want to return. E.g.:

Run Consumer

Your inherited class of consumer of Consumer should look like this:

Then you can run the Consumer:

Just like a Producer class this one also has a setQueueName() method. So you can set the queue name
when new instance is being created or later by using method.

Console information

Additionally there are two methods:

consoleMessage($req)

It's used to display message in a console. It has one parameter $req - containing all the info about the recievied message. By default this method returns string: New request so if a new message will be delivered the console should print:

Whole message could be changed by overriding consoleInfo() method. ATTENTION! Don't forget to run Consumer class first (it will create the queue on RabbitMQ server)

License

MIT


All versions of rabbitmq_rpc with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2
vlucas/phpdotenv Version ^3.6
php-amqplib/php-amqplib Version ^2.10
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 tzmudz/rabbitmq_rpc contains the following files

Loading the files please wait ....