Download the PHP package loffel/laravel-rabbitmq without Composer

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

Build Status Scrutinizer Code Quality Code Coverage Total Downloads

Laravel RabbitMQ

A simple rabbitmq library for laravel based on Publish–Subscribe pattern where the subscriber is the Consumer.

Table of Contents

  1. Install
  2. Configure

    2.1. Connections

    2.2. Queues

    2.3. Exchanges

    2.4. Publishers

    2.5. Consumers

  3. Usage

    3.1. Publishing a message

    3.2. Consuming a message

    3.3. Available CLI commands

    3.4. Custom Message Processor

  4. Contribute

1. Install

Run:

For Laravel version 5.5 or higher the library should be automatically loaded via Package discovery.

For Laravel versions below 5.5 you need to add the service provider to app.php:

2. Configure

The configuration files has 5 main nodes: connections, exchanges, queues, publishers, consumers.

They are used in the following mode:

Example config:

2.1. Connections

Connection attributes:

Attribute Type Default value Description
hostname string 127.0.0.1 The host for the RabbitMQ instance
port integer 5672 The port for the RabbitMQ instance
username string guest Default's RabbiqMQ username
password string guest Default's RabbiqMQ username
vhost string / RabbitMQ Virtual Host. Read more here.
lazy boolean true Setting it lazy will only make the connection when an action that needs the connection willl be called
read_write_timeout integer 3 TTL for read/write operations.
connect_timeout integer 3 TTL for the connection
heartbeat integer 0 Whether to check the socket connection periodically. Read more here.
keep_alive boolean false Whether to use system's keep alive property. Read more here.

2.2. Queues

Queue main nodes:

Node key Type Description
connection string The reference to the connection that should be used.
name string The actual name of the queue on RabbitMQ
attributes array Optional attributes for the queue

Queue attributes

Attribute key Type Default Description
passive boolean false This is an AMQP attribute. Read about [here] (https://www.rabbitmq.com/amqp-0-9-1-reference.html)
durable boolean false Same as passive attribute
exclusive boolean false Same as passive attribute
auto_delete boolean false Same as passive attribute
internal boolean false Same as passive attribute
nowait boolean false Same as passive attribute
auto_create boolean false Whether should try to create (and bind) the queue when queried.
throw_exception_on_redeclare boolean true Throw exception when re-declare of the queue fails
throw_exception_on_bind_fail boolean true Throw exception when cannot create the bindings
bind array empty Whether should bind to an exchange: See Example 1.

Example 1:

2.3. Exchanges

Exchange main nodes:

Node key Type Description
connection string The reference to the connection that should be used.
name string The actual name of the queue on RabbitMQ
attributes array Optional attributes for the exchange

Exchange attributes

Attribute key Type Default Description
exchange_type string - Mandatory The type of the exchange (direct / fanout / topic / headers). View description [here] (https://www.rabbitmq.com/tutorials/amqp-concepts.html)
passive boolean false This is an AMQP attribute. Read about [here] (https://www.rabbitmq.com/amqp-0-9-1-reference.html)
durable boolean false Same as passive attribute
auto_delete boolean false Same as passive attribute
internal boolean false Same as passive attribute
nowait boolean false Same as passive attribute
auto_create boolean false Whether should try to create (and bind) the queue when queried.
throw_exception_on_redeclare boolean true Throw exception when re-declare of the queue fails
throw_exception_on_bind_fail boolean true Throw exception when cannot create the bindings
bind array empty Whether should bind to an exchange: See Example 2.

Example 2:

2.4. Publishers

A publisher push a message on an exchange (but it can also push it on a queue). Defining a publishers:

2.5. Consumers

A consumer will alway get message from a queue. Define a consumer:

Field Type Description
queue string Reference of the defined queue block.
prefetch_count int Default: 1. The number of the message that a cosumer will grab without ack. Read more here
passive boolean false This is an AMQP attribute. Read about [here] (https://www.rabbitmq.com/amqp-0-9-1-reference.html)
durable boolean false Same as passive attribute
auto_delete boolean false Same as passive attribute
internal boolean false Same as passive attribute
nowait boolean false Same as passive attribute
auto_create boolean false Whether should try to create (and bind) the queue when queried.
throw_exception_on_redeclare boolean true Throw exception when re-declare of the queue fails
throw_exception_on_bind_fail boolean true Throw exception when cannot create the bindings
bind array empty Whether should bind to an exchange: See Example 2.

3. Usage

After configuring, you should end up with a configuration file laravel_rabbitmq.php similar to this one:

3.1. Publishing a message

Example of usage in code:

Optional, there is a command that can be used to publish a message.

Note: At the moment, routing key in CLI is not supported.

3.2. Consuming a message

Consuming message should be done by running a command in deamon mode. While PHP is not intended to do that, you can use supervisor for that.

The flow of the consummer is rather simple: CLI Consumers -> Get message -> Passes it to the message_processor key from configuration.

A message processor is a class that implements NeedleProject\LaravelRabbitMq\Processor interface. If you do no want to handle acknowledgement you can extend \NeedleProject\LaravelRabbitMq\Processor\AbstractMessageProcessor which require implementation of processMessage(AMQPMessage $message): bool method.

You message_processor key is runned by laravel's app command for build of the class.

Start the message consumer/listener:

Running consumers with limit (it will stop when one of the limits are reached)

This tells the consumer to stop if it run for 1 minute or consumer 100 messages or has reached 64MB of memory usage.

3.3. Available commands

When running php artisan a new namespace will be present:

Name Description Example
rabbitmq:consume Consummer command php artisan rabbitmq:consume [consumer-name] --time=60 --messages=100 --memory=64 Where --time/messages/memory are optional. Default values are 60 seconds, 100 messages and 64MB of RAM usage
rabbitmq:delete-all Delete all queues, exchanges and binds that are defined in entities AND referenced to either a publisher or a consumer
rabbitmq:list List all entities by type: publishers consumers
rabbitmq:publish Publish one message using a consumer php artisan rabbitmq:publish [publisher-name] message
rabbitmq:setup Creates all queues and exchanges php artisan rabbitmq:setup or php artisan rabbitmq:setup --force. NOTE When using force, all queues and exchanges will be deleted first and then re-created.

3.4. Custom Message Processor

At the current moment there is the posibility to either implement the MessageProcessorInterface class or extend the AbstractMessageProcessor.

When using the AbstractMessageProcessor, you will have access to extra API than can be used in your processMessage():

4. Contribute

You are free to contribute by submiting pull request or reporting any issue in Github. At the current stage of the project, no contribution procedure is defined.


All versions of laravel-rabbitmq with dependencies

PHP Build Version
Package Version
Requires php Version 7.*|8.*
php-amqplib/php-amqplib Version >=2.7|3.*
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 loffel/laravel-rabbitmq contains the following files

Loading the files please wait ....