Created
September 11, 2014 09:00
-
-
Save Jmoati/23018c80f50e51c459d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once(__DIR__ . '/../vendor/autoload.php'); | |
use Swarrot\Broker\MessageProvider\PeclPackageMessageProvider; | |
use Swarrot\Broker\MessagePublisher\PeclPackageMessagePublisher; | |
use Swarrot\Broker\Message; | |
use Swarrot\Processor\ProcessorInterface; | |
use Swarrot\Processor\Stack\Builder; | |
use Swarrot\Consumer; | |
$connection = new \AMQPConnection(); | |
$connection->connect(); | |
$channel = new \AMQPChannel($connection); | |
$exchange = new \AMQPExchange($channel); | |
$exchange->setName('exchange-loop'); | |
$exchange->setType(AMQP_EX_TYPE_DIRECT); | |
//$exchange->setFlags(AMQP_DURABLE); | |
$exchange->declareExchange(); | |
$queue = new \AMQPQueue($channel); | |
$queue->setName('queue-loop'); | |
//$queue->setFlags(AMQP_DURABLE); | |
$queue->declareQueue(); | |
$queue->bind($exchange->getName(), 'loop'); | |
$provider = new PeclPackageMessagePublisher($exchange); | |
$provider->publish(new Message('azerty', array(/*'delivery_mode' => AMQP_DURABLE*/)), 'loop'); | |
class Processor implements ProcessorInterface | |
{ | |
public function process(Message $message, array $options) | |
{ | |
throw new \Exception('Fail'); | |
} | |
} | |
$messageProvider = new PeclPackageMessageProvider($queue); | |
$stack = new Builder(); | |
$stack | |
->push('Swarrot\Processor\ExceptionCatcher\ExceptionCatcherProcessor') // <--- SHOULD BE ALWAYS AT THE END FOR NO BLOCKING | |
->push('Swarrot\Processor\MaxMessages\MaxMessagesProcessor') // <--- LIMIT DON'T WORK DUE TO PREVIOUS LINE | |
->push('Swarrot\Processor\Ack\AckProcessor', $messageProvider) | |
->push('Swarrot\Processor\SignalHandler\SignalHandlerProcessor') // <--- SIGNAL DON'T WORK DUE TO FIRST STACK | |
; | |
$processor = $stack->resolve(new Processor()); | |
$consumer = new Consumer($messageProvider, $processor); | |
$consumer->consume(array( | |
'requeue_on_error' => true, | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment