PHP code example of ipunkt / laravel-rabbitmq

1. Go to this page and download the library: Download ipunkt/laravel-rabbitmq library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ipunkt / laravel-rabbitmq example snippets


'YOUR-QUEUE-IDENTIFIER' => [
	'host' => 'YOUR-RABBITMQ-HOST',
	'port' => 5672,
	'user' => 'guest',
	'password' => 'guest',
	'name' => '',
	'durable' => false,
	'exchange' => [
		'exchange' => 'YOUR-EXCHANGE-NAME',
		'type' => 'YOUR-EXCHANGE-TYPE',
		'passive' => false,
		'durable' => false,
		'auto_delete' => false,
		'internal' => false,
		'nowait' => false,
		'arguments' => null,
		'ticket' => null,
	],
	'bindings' => [
		//  key => event name
		// ROUTING-KEY maps to an LARAVEL-EVENT-CLASS-NAME
	],
],
'logging' => [
	'enable' => false,
	/**
	 * Set this to false if you do not wish to log Exceptions or Throwables from `rabbitmq:listen`
	 */
	'event-errors' => true,
	'queue-identifier' => 'default',
	'extra-context' => [],
],

$rabbitMQ = new \Ipunkt\LaravelRabbitMQ\RabbitMQ();// or from DI container
$rabbitMQ->onQueue('YOUR-QUEUE-IDENTIFIER') // Queue Identifier has to be configured within the laravel-rabbitmq.php
	->data(['users' => $users]) // anything, gets json_encoded
	->publish('ROUTING-KEY'); // publish to a routing key, the listener is subscribed to
bash
php artisan rabbitmq:listen YOUR-QUEUE-IDENTIFIER