Download the PHP package girni/laravel-rabbitmq without Composer

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

Laravel RabbitMQ package that extends https://github.com/vyuldashev/laravel-queue-rabbitmq to support microservice communication.

Installation

In your composer.json file add these lines of codes under require section and repositories:

After that changes simply run composer install or composer update girni/laravel-rabbitmq to make it installed.

The package will automatically register itself.

Add connection to config/queue.php:

Publish laravel-rabbitmq.php config file:

Usage

Define a queue in .env file

To ensure that our communication between applications runs smoothly, it is necessary to define separate queues for each application. We can do it in .env file.

Defining a RABBIT_QUEUE will result that our application will consume a messages only from that queue. By making different queues for each application we have guarantee our messages won't be processed in incorrect way by other application.

Creating producer

Producing means nothing more than sending. A class that sends messages is a producer. Our producer classess should be as simple as it's only possible. It should contains a message data passed by it's constructor and the ::name() that must be implemented due to implemented contract.

::name() value is very important, it's being used to recognize which consumer we should run to handle the produced message.

Dispatching message

To dispatch a message to a RabbitMQ we can use laravel dispatcher in several ways. More you can read here https://laravel.com/docs/9.x/queues#dispatching-jobs

It's important to define a queue on which we want to send a message by using ::onQueue() method. As it's mentioned before, each application should consume the messages ONLY from its own queue. So if we want our message to be processed by another application we need to send it to this application's queue.

Message structure for non Laravel sender

JSON example:

Creating a consumer

Consumer class is nothing more than a "Handler" for a producer. This class is obliged to process the data that was sent by producer.

Register consumer

In your application in config\laravel-rabbitmq.php file in consumers array you have to register each consumer you want to use in your application. Your config should look like:

Consuming messages

To start consuming produced messages we need to run our queue:

or standard laravel procedure

Advanced usage - Custom Message class

As a standard message store we implemented Girni\LaravelRabbitMQ\Message\BaseMessage::class that has simple interface which operates on array keys.

It contains helper methods such as ::get($key), ::set($key) to help client get/set data from/to a message.

However, in some cases our message can be very complex, and we would prefer to store its data in dedicated class (DTO) with object-oriented interface.

We can do it by adding Girni\LaravelRabbitMQConsumer\HasCustomMessage interface to our consumer class, that comes with a method ::message(). In the body of this method you should pass a FQCN to your class.

IMPORTANT: Make sure your DTO class implements Girni\LaravelRabbitMQ\Message\MessageInterface. The whole logic in which our library will create an object is hiding in ::fromArray(array $data) method.

Testing

Changelog

Please see CHANGELOG for more information what has changed recently.

License

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


All versions of laravel-rabbitmq with dependencies

PHP Build Version
Package Version
Requires php Version >=8.0
illuminate/support Version ^9.0|^10.0
vladimir-yuldashev/laravel-queue-rabbitmq Version ^13.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 girni/laravel-rabbitmq contains the following files

Loading the files please wait ....