Пример #1
0
 /**
  * @param Queue $queue
  *
  * @return $this
  */
 public function addQueue(Queue $queue)
 {
     if ($this->hasQueue($queue->name())) {
         throw new \InvalidArgumentException(sprintf('Queue "%s" already defined', $queue->name()));
     }
     $this->queues[$queue->name()] = $queue;
     return $this;
 }
Пример #2
0
 /**
  */
 public function initialize()
 {
     if ($this->initialized) {
         return;
     }
     $this->initialized = true;
     $this->exchange->initialize();
     $this->queue->initialize();
     $this->channel->queue_bind($this->queue->name(), $this->exchange->name());
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function register(Container $pimple)
 {
     $pimple['rabbitmq'] = array();
     $pimple['rabbitmq.config'] = function () use($pimple) {
         return array_merge(array('host' => 'localhost', 'port' => 5672, 'user' => 'guest', 'password' => 'guest', 'vhost' => '/', 'prefetch_count' => null), $pimple['rabbitmq']);
     };
     $pimple['rabbitmq.connection'] = function () use($pimple) {
         $config = $pimple['rabbitmq.config'];
         return new Connection($config['host'], $config['port'], $config['user'], $config['password'], $config['vhost']);
     };
     $pimple['rabbitmq.channel'] = function () use($pimple) {
         $config = $pimple['rabbitmq.config'];
         $channel = $pimple['rabbitmq.connection']->channel();
         if ($config['prefetch_count'] !== null) {
             $channel->basic_qos(null, $config['prefetch_count'], true);
         }
         return $channel;
     };
     $pimple['rabbitmq.manager'] = function () use($pimple) {
         $manager = new Manager($pimple['rabbitmq.channel']);
         $config = array_merge(array('exchanges' => array(), 'queues' => array(), 'bindings' => array()), $pimple['rabbitmq']);
         foreach ($config['exchanges'] as $name => $parameters) {
             $manager->addExchange(Exchange::configure($pimple['rabbitmq.channel'], $name, $parameters ?: array()));
         }
         foreach ($config['queues'] as $name => $parameters) {
             $manager->addQueue(Queue::configure($pimple['rabbitmq.channel'], $name, $parameters ?: array()));
         }
         foreach ($config['bindings'] as $parameters) {
             if (!isset($parameters['exchange']) || !isset($parameters['queue'])) {
                 throw new \InvalidArgumentException("Every binding should have 'exchange' and 'queue' parameters");
             }
             $manager->bind($parameters['exchange'], $parameters['queue']);
         }
         return $manager;
     };
 }
Пример #4
0
 public function consume()
 {
     $this->queue->consume(array($this->service, 'execute'), $this->tag, array('no_local' => $this->noLocal, 'no_ack' => $this->noAck, 'exclusive' => $this->exclusive, 'no_wait' => $this->noWait));
 }