The application is built with Laravel zero.
This repository holds examples for:
- Clone the repository.
- Run
composer install
to install project dependencies. - Copy
.env.example
to.env
. - Populate your credentials.
If you are not familiar with .env
file, .env
holds credentials for the project. The environments values are referred
in the code. For this project, it should be inside the config/amqp.php
file.
php amqp amqp:publish
or ./amqp amqp:publish
command can be used to publish messages to RabbitMQ.
Class that is responsible for the command is in app/Commands/AmqpPublishCommand.php
. Go through the file if you need
to dig in.
The command has the following options available. php amqp amqp:publish --help
should show you list of help.
Description:
Publish message to RabbitMQ
Usage:
amqp:publish [options]
Options:
--msg Message you want to pass
--exchange Exchange to publish the message
--type Exchange Type
--rk Routing key
--dde Do not declare exchange
--i Input values with interaction
--h Include header when passing message
--np Transient / Non-persistent message
--msg
optional. If not provided, generates random json string.--exchange
optional. Name of the exchange. Defaultexample.direct
.--type
optional. Type of the exchange. Defaultdirect
.--rk
optional. Routing key. Default''
(empty string).--dde
optional switch. Do not declare exchange. Defaultfalse
meaning tries to declare exchange.--i
optional switch. Defaultfalse
. If used, provide values using interaction.--h
optional switch. If you want to useheaders
type of exchange, you must have to provide headers using this flag.--np
optional switch. By default, all the messages to the exchange is PERSISTENT. If you want to send ** Non-Persistent** message, you can use this flag.
php amqp amqp:publish:laravel
or ./amqp amqp:publish:laravel
command can be used to publish messages to RabbitMQ
using anik/laravel-amqp.
Rest of the options remains the same as above
php amqp amqp:consume
or ./amqp amqp:consume
command can be used to retrieve messages from RabbitMQ.
Class that is responsible for the command is in app/Commands/AmqpConsumeCommand.php
. Go through the file if you need
to dig in.
The command has the following options available. php amqp amqp:consume --help
should show you list of help.
Description:
Consume message from RabbitMQ
Usage:
amqp:consume [options]
Options:
--exchange Exchange to listen
--type Exchange Type
--queue Queue to listen
--bk Binding key
--dde Do not declare exchange
--ddq Do not declare queue
--i Input values with interaction
--ct Consumer tag
--h Include header
--ack Acknowledge received message
--reject Reject received message
--requeue Requeue received message
--exchange
optional. Name of the exchange. Defaultexample.direct
.--type
optional. Type of the exchange. Defaultdirect
.--queue
optional. Name of the queue. Defaultexample.{type}.queue
.--bk
optional. Binding key. Default''
(empty string).--dde
optional switch. Do not declare exchange. Defaultfalse
meaning tries to declare exchange.--ddq
optional switch. Do not declare queue. Defaultfalse
meaning tries to declare queue.--i
optional switch. Defaultfalse
. If used, provide values using interaction.--ct
optional. Consumer tag. Defaultamqp.consumer.tag
.--h
optional switch. If you want to useheaders
type of exchange, you must have to provide headers using this flag.--ack
optional switch. If provided, will acknowledge messages upon receive. PRIORITY 1--reject
optional switch. If provided, will reject messages upon receive. PRIORITY 2--requeue
optional switch. If provided, will nack messages upon receive. PRIORITY 3
php amqp amqp:consume:laravel
or ./amqp amqp:consume:laravel
command can be used to retrieve messages from RabbitMQ
using anik/laravel-amqp.
Rest of the options remains the same as above
- If none of the
--ack
,--reject
,--requeue
switches are used, as the consumer creates connection with the acknowledgement required, messages will persist. - It's possible to try various combinations with the above commands. Try playing with them.