Exemple #1
0
<?php

include __DIR__ . './../vendor/autoload.php';
use Kemer\Amqp;
use Kemer\Amqp\Addons as AmqpAddons;
use Symfony\Component\EventDispatcher\GenericEvent;
$broker = new Amqp\Broker(getenv("AMQP_HOST") ?: "rabbit.docker", getenv("AMQP_PORT") ?: 5672, getenv("AMQP_LOGIN") ?: 'guest', getenv("AMQP_PASSWORD") ?: 'guest');
$dispatcher = new Amqp\Dispatcher();
$dispatcher->addSubscriber(new AmqpAddons\PostponeSubscriber($broker));
$dispatcher->addSubscriber(new AmqpAddons\DeadLetterSubscriber($broker));
// Add event listeners
$dispatcher->addListener('kernel.waits', [new App\Listener(), "onMessage"]);
$dispatcher->addListener("kernel.*", [new App\Listener(), "onKernel"]);
$dispatcher->addListener('#', [new App\Listener(), "onAll"]);
// Add event subscriber
$dispatcher->addSubscriber(new App\Subscriber());
// dispatch local messages
// $dispatcher->dispatch("some.kernel", new Amqp\PublishEvent());
$consumer = new Amqp\Consumer($dispatcher);
/**
 * Listen on shared queue (load balanced)
 *
 * @throws AMQPQueueException if queue does not exists
 */
//$queue = $broker->declareQueue(AMQP_PASSIVE, "some-queue");
$queue = $broker->queue(AMQP_DURABLE, "some-queue");
$queue->setArgument("x-dead-letter-exchange", "some-exchange-dlx");
$queue->declareQueue();
// $consumer->listen($queue);
// Listen on temporary queue - and bind it to exchange
//$queue = $broker->declareQueue(AMQP_AUTODELETE);
Exemple #2
0
<?php

include __DIR__ . './../vendor/autoload.php';
use Kemer\Amqp;
$broker = new Amqp\Broker("rabbit.docker", 5672, 'guest', 'guest');
$dispatcher = new Amqp\Dispatcher();
$dispatcher->addSubscriber(new Amqp\Facade\PostponeSubscriber($broker));
$dispatcher->addSubscriber(new Amqp\Facade\DeadLetterSubscriber($broker));
$dispatcher->addListener("#", new Amqp\Publisher\QueuePublisher($broker), 1000);
$dispatcher->addListener("#", new Amqp\Publisher\ExchangePublisher($broker), 1001);
// Add event listeners
$dispatcher->addListener('kernel.message', [new App\Listener(), "onMessage"]);
$dispatcher->addListener("kernel.*", [new App\Listener(), "onKernel"]);
$dispatcher->addListener('kernel.#', [new App\Listener(), "onAll"]);
// Add event subscriber
$dispatcher->addSubscriber(new App\Subscriber());
// Send discover request
$dispatcher->dispatch("some-kernel", new Amqp\PublishEvent());
$consumer = new Amqp\Consumer($dispatcher);
// Listen on named queue
$consumer->listen($broker->declareQueue(AMQP_DURABLE, "error-queue"));
// Listen on existing shared queue (load balanced)
$consumer->listen($broker->declareQueue(AMQP_PASSIVE, "existing-queue"));
Exemple #3
0
<?php

include __DIR__ . './../vendor/autoload.php';
use Kemer\Amqp;
use Kemer\Amqp\Addons as AmqpAddons;
use Symfony\Component\EventDispatcher\Event as SymfonyEvent;
$broker = new Amqp\Broker("rabbit.docker", 5672, 'guest', 'guest');
$dispatcher = new Amqp\Dispatcher();
$dispatcher->addListener("#", new Amqp\Publisher\QueuePublisher($broker), 1000);
$dispatcher->addListener("#", new Amqp\Publisher\ExchangePublisher($broker), 1001);
$dispatcher->addSubscriber(new AmqpAddons\MonologSubscriber($logger = new Monolog\Logger("AMQP")));
$logger->pushHandler($handler = new Monolog\Handler\ErrorLogHandler());
$handler->setFormatter(new Monolog\Formatter\LineFormatter($output = " %level_name% %message% %context% ", $dateFormat = "g:i" . false, false));
$emiter = new App\Emiter($dispatcher);
// Publish queue-get command
$emiter->queueGetCommand("some-exchange", AMQP_DURABLE, "some-exchange-dlx");
// Publish message to exchange
$emiter->publishToExchange("some-exchange");
/**
 * Declare default exchnge
 */
$exchange = $broker->declareExchange(AMQP_DURABLE, "some-exchange", AMQP_EX_TYPE_TOPIC);
$dispatcher->addListener("#", new Amqp\Publisher\DefaultExchangePublisher($exchange, $broker), 1001);
/* Publish message to default exchange */
$emiter->publishToDefaultExchange();
/* Publish message to queue */
// $emiter->publishToQueue();
/* Publish local messages */
// $emiter->publishLocal();
/* Publish error messages */
// $emiter->publishErroring();