Download the PHP package djereg/laravel-rabbitmq without Composer

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

THIS PACKAGE IS PRIMARILY INTENDED FOR INTERNAL/PRIVATE USE IN OWN PROJECTS. IF IT MEETS YOUR NEEDS, FEEL FREE TO USE IT, BUT IN CASE OF ANY MODIFICATION REQUESTS, I WILL CONSIDER MY OWN NEEDS FIRST.

It is still in a very early development phase, so I do not really recommend using it for now, because anything can change on it at any time and previous functions may break.

The package is part of the rabbitmq-multiverse.

Table of Contents

Description

This package is an intermediate layer between RabbitMQ and Laravel Queue.

The package is based on vladimir-yuldashev/laravel-queue-rabbitmq package, which adds RabbitMQ as a queue driver to Laravel.

This package extends the functionality of the original package by adding the ability to send and receive events and RPC calls through RabbitMQ messages.

Motivation

Since the microservice architecture has become very popular, I needed a library that provides the possibility of communicating with services written in different programming languages or frameworks.

Laravel has a powerful queue system, but it is a closed Laravel-only system. This package allows you to communicate through messages between Laravel and/or other non-Laravel microservices.

On the top of simple JSON messages, utilizes the Laravel Queue and Event system, which perfectly does the rest of the job.

Usage

Installation

You can install this package via composer using this command:

The package will automatically register itself.

Configuration

The configuration is done through environment variables.

Starting the consumer

To start the consumer, just run the following command:

Events

Provides an event based asynchronous communication between services.

Dispatching events

Create an event class that extends MessagePublishEvent provided by this package.

And after just dispatch the event like any other Laravel event.

Listening to events

Create an event listener that extends MessageEventListener provided by this package.

The working mechanism is a little bit different from the Laravel event listeners. First, you have to specify the events you want to listen to in the $listen property. Next, instead of public handle() method, you have to define the onEvent() method. This is because the handle() method is already used under the hood by the base MessageEventListener class.

Errors in event listeners

Since the event listeners are processed synchronously by default, if an error occurs, the job will fail and will be retried by the retry mechanism, if it is enabled and configured.

If multiple listeners listening to the same event, the processing will stop at the first listener that throws an error and the rest of the listeners will not be processed.

You have multiple options to prevent this behavior:

Processing events asynchronously

The events are processed synchronously by default, but you can process them asynchronously by implementing the ShouldQueue interface.

Subscribing to events

When starting the consumer, it automatically creates the exchange and the queue if they do not exist, but to register the events listening to, you have to modify the EventServiceProvider to extend the EventServiceProvider provided by this package. In Laravel 11 the EventServiceProvider does not exist by default, so you have to create and register it manually. See the example below.

The service provider discovers all event listeners from the app/Listeners directory and the routing keys will be bound automatically when the consumer started.

RPC

A synchronous-like communication between services.

Uses the JSON-RPC 2.0 protocol for communication.

Registering clients

To call remote procedures, you have to create an instance of the Client class and inject it into the service where you want to use it. The best way is to do it in a service provider.

Anyway, you can create the client instance wherever you want, but remember to pass the queue connection as the second argument.

Calling remote procedures

In the service where you injected the client, you can call the remote procedures.

Registering remote procedures

Register the ProcedureServiceProvider provided by this package. The service provider will automatically discover all procedures in the app/Procedures directory by default. The automatic discovery runs only when the application is started in console mode.

If you want to customize the service provider, you can create your own that extends the ProcedureServiceProvider class provided by this package and register it.

Handling procedure calls

When the service provider is registered, you can create the procedures in the app/Procedures directory. Create a class that extends the Procedure class and define the method property with the name of the procedure.

You can define the __invoke() or handle() method to process the procedure call. If both methods are defined, an exception will be thrown as multiple handlers are not allowed for one procedure. The same applies to multiple procedure classes with the same name.

How the procedure calls are processed?

When a procedure call message is received, the request body is passed to datto/php-json-rpc server component, which processes the request and calls the matching procedure, and finally returns the response object, which is sent back to the requester.

Laravel Queue

The Laravel Queue is also supported by this package. You can send jobs to the queue and the consumer will process them as the original Laravel queue worker.

Lifecycle Events

The package emits events during the message processing.

MessagePublishing

Dispatched before the message is being published.

MessagePublished

Dispatched after the message is published.

MessageProcessing

Dispatched before the message is being processed.

MessageProcessed

Dispatched after the message is processed.

Known Issues

License

MIT licensed


All versions of laravel-rabbitmq with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
ext-pcntl Version *
datto/json-rpc Version ^6.1
illuminate/contracts Version ^10.0 || ^11.0
illuminate/queue Version ^10.0 || ^11.0
illuminate/support Version ^10.0 || ^11.0
php-amqplib/php-amqplib Version ^3.0
vladimir-yuldashev/laravel-queue-rabbitmq Version ^13.0 || ^14.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 djereg/laravel-rabbitmq contains the following files

Loading the files please wait ....