1. Go to this page and download the library: Download vinelab/bowler 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/ */
// Initialize a Bowler Connection
$connection = new Vinelab\Bowler\Connection();
// Initialize a Producer object with a connection
$bowlerProducer = new Vinelab\Bowler\Producer($connection);
// Setup the producer's exchange name and other optional parameters: exchange type, passive, durable, auto delete and delivery mode
$bowlerProducer->setup('reporting_exchange', 'direct', false, true, false, 2);
// Send a message with an optional routingKey
$bowlerProducer->send($data, 'warning');
use Vinelab\Bowler\Producer;
class DoSomethingJob extends Job
{
protected $data;
public function __construct($data)
{
$this->data = $data;
}
public function handle(Producer $producer)
{
$producer->setup('reporting_exchange');
$producer->send(json_encode($this->data));
}
}
// This is an example handler class
namespace App\Messaging\Handlers;
class AuthorHandler {
public function handle($msg)
{
echo "Author: ".$msg->body;
}
public function handleError($e, $broker)
{
if($e instanceof InvalidInputException) {
$broker->rejectMessage();
} elseif($e instanceof WhatEverException) {
$broker->ackMessage();
} elseif($e instanceof WhatElseException) {
$broker->nackMessage();
} else {
$msg = $broker->getMessage();
if($msg->body) {
//
}
}
}
}
bowler:consume
queueName : The queue NAME
--N|exchangeName : The exchange NAME. Defaults to queueName.
--T|exchangeType : The exchange TYPE. Supported exchanges: fanout, direct, topic. Defaults to fanout.
--K|bindingKeys : The consumer\'s BINDING KEYS array.
--p|passive : If set, the server will reply with Declare-Ok if the exchange and queue already exists with the same name, and raise an error if not. Defaults to 0.
--d|durable : Mark exchange and queue as DURABLE. Defaults to 1.
--D|autoDelete : Set exchange and queue to AUTO DELETE when all queues and consumers, respectively have finished using it. Defaults to 0.
--deadLetterQueueName : The dead letter queue NAME. Defaults to deadLetterExchangeName.
--deadLetterExchangeName : The dead letter exchange NAME. Defaults to deadLetterQueueName.
--deadLetterExchangeType : The dead letter exchange TYPE. Supported exchanges: fanout, direct, topic. Defaults to fanout.
--deadLetterRoutingKey : The dead letter ROUTING KEY.
--messageTTL : If set, specifies how long, in milliseconds, before a message is declared dead letter.
public function handle($msg)
{
switch ($msg->delivery_info['routing_key']) {
case 'key 1': //do something
break;
case 'key 2': //do something else
break;
}
}
// Initialize a Bowler object with the rabbitmq server ip and port
$connection = new Bowler\Connection();
// Initialize a Pubisher object with a connection and a routingKey
$bowlerPublisher = new Publisher($connection);
// Publish the message and set its
// Initialize a Bowler object with the rabbitmq server ip and port
$connection = new Bowler\Connection();
// Initialize a Dispatcher object with a connection
$dispatcher = new Dispatcher($connection);
// Publish the message and set its
// catch all the cows in the "farm" exchange
Registrator::subscriber('monitoring', 'App\Messaging\Handlers\MonitoringMessageHandler', [
'*.cow.*',
], 'farm');