protected function execute(InputInterface $input, OutputInterface $output)
 {
     $output->writeln(sprintf('Move messages from queue "%s" (vhost: "%s") to exchange "%s" with routingKey "%s" (vhost: "%s")', $input->getArgument('from_queue'), $input->getArgument('from_vhost'), $input->getArgument('to_exchange'), $input->getArgument('to_routing_key'), $input->getArgument('to_vhost')));
     $fromChannel = $this->getChannel($input->getArgument('from_connection'), $input->getArgument('from_vhost'));
     if (null === ($toConnectionName = $input->getOption('to_connection'))) {
         $toChannel = $this->getChannel($input->getArgument('from_connection'), $input->getArgument('to_vhost'));
     } else {
         $toChannel = $this->getChannel($input->getOption('to_connection'), $input->getArgument('to_vhost'));
     }
     $queue = new \AMQPQueue($fromChannel);
     $queue->setName($input->getArgument('from_queue'));
     $exchange = new \AMQPExchange($toChannel);
     $exchange->setName($input->getArgument('to_exchange'));
     $messageProvider = new PeclPackageMessageProvider($queue);
     $messagePublisher = new PeclPackageMessagePublisher($exchange);
     $options = array();
     $stack = new \Swarrot\Processor\Stack\Builder();
     if (0 !== ($max = (int) $input->getOption('max-messages'))) {
         $stack->push('Swarrot\\Processor\\MaxMessages\\MaxMessagesProcessor');
         $options['max_messages'] = $max;
     }
     $stack->push('Swarrot\\Processor\\Insomniac\\InsomniacProcessor');
     $stack->push('Swarrot\\Processor\\Ack\\AckProcessor', $messageProvider);
     $processor = $stack->resolve(new MoveProcessor($messagePublisher, $input->getArgument('to_routing_key')));
     $consumer = new Consumer($messageProvider, $processor);
     $consumer->consume($options);
 }
示例#2
0
 public function test_it_call_processor_if_its_Sleepy()
 {
     $provider = $this->prophesize('Swarrot\\Broker\\MessageProvider\\MessageProviderInterface');
     $processor = $this->prophesize('Swarrot\\Processor\\SleepyInterface');
     $message = new Message('body', array(), 1);
     $provider->get()->willReturn($message);
     $processor->sleep(Argument::type('array'))->willReturn(null);
     $processor->process(Argument::type('Swarrot\\Broker\\Message'), Argument::type('array'))->willReturn(false);
     $consumer = new Consumer($provider->reveal(), $processor->reveal());
     $this->assertNull($consumer->consume());
 }
示例#3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getContainer();
     $gate = $input->getArgument('gate');
     $kernel = $container->get('kernel');
     $broker = $container->get('wisembly.amqp.broker');
     $logger = $container->get('monolog.logger.consumer');
     $gate = $container->get('wisembly.amqp.gates')->get($gate);
     $provider = $broker->getProvider($gate);
     $producer = $broker->getProducer($gate);
     $processor = new CommandProcessor($logger, new ProcessBuilder(), $provider, $producer, $container->getRootDir() . '/app/console', $kernel->getEnvironment(), true === $input->getOption('disable-verbosity-propagation') ? OutputInterface::VERBOSITY_QUIET : $output->getVerbosity());
     // if we want a rpc mechanism, let's wrap a rpc server processor
     if (true === $input->getOption('rpc')) {
         $processor = new RpcServerProcessor($processor, $producer, $logger);
     }
     // Wrap processor in an Swarrot ExceptionCatcherProcessor to avoid breaking processor if an error occurs
     $consumer = new Consumer($provider, new ExceptionCatcherProcessor($processor, $logger));
     $consumer->consume(['poll_interval' => $input->getOption('poll-interval')]);
 }
示例#4
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use Swarrot\Consumer;
use Swarrot\Broker\PeclPackageMessageProvider;
use Swarrot\Broker\Message;
use Swarrot\Processor\ProcessorInterface;
class Processor implements ProcessorInterface
{
    public function process(Message $message, array $options)
    {
        printf("Consume message #%d\n", $message->getId());
    }
}
$connection = new \AMQPConnection();
$connection->connect();
$channel = new \AMQPChannel($connection);
$queue = new \AMQPQueue($channel);
$queue->setName('global');
$messageProvider = new PeclPackageMessageProvider($queue);
$consumer = new Consumer($messageProvider, new Processor());
$consumer->consume();
示例#5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $queue = $input->getArgument('queue');
     $connection = $input->getArgument('connection');
     $factory = $this->getContainer()->get('swarrot.factory.default');
     $messageProvider = $factory->getMessageProvider($queue, $connection);
     $stack = new Builder();
     if (array_key_exists('signal_handler', $this->processorStack)) {
         $stack->push($this->processorStack['signal_handler'], $this->logger);
     }
     if (array_key_exists('max_messages', $this->processorStack)) {
         $stack->push($this->processorStack['max_messages'], $this->logger);
     }
     if (array_key_exists('max_execution_time', $this->processorStack)) {
         $stack->push($this->processorStack['max_execution_time'], $this->logger);
     }
     if (array_key_exists('exception_catcher', $this->processorStack) && !$input->getOption('no-catch')) {
         $stack->push($this->processorStack['exception_catcher'], $this->logger);
     }
     if (array_key_exists('ack', $this->processorStack)) {
         $stack->push($this->processorStack['ack'], $messageProvider, $this->logger);
     }
     if (array_key_exists('retry', $this->processorStack) && !$input->getOption('no-retry')) {
         $exchange = 'retry';
         if (isset($this->extras['retry_exchange'])) {
             $exchange = $this->extras['retry_exchange'];
         }
         $messagePublisher = $factory->getMessagePublisher($exchange, $connection);
         $stack->push($this->processorStack['retry'], $messagePublisher, $this->logger);
     }
     $processor = $stack->resolve($this->processor);
     $optionsResolver = new OptionsResolver();
     $optionsResolver->setOptional(array('queue', 'connection'));
     $consumer = new Consumer($messageProvider, $processor, $optionsResolver);
     $consumer->consume($this->getOptions($input));
 }