/**
  * @param object $consumer
  *
  * @throws ConsumerException
  */
 public function registerConsumer($consumer)
 {
     $type = gettype($consumer);
     if ($type !== 'object') {
         throw new ConsumerException(sprintf('Expected argument of type "object", "%s" given', $type));
     }
     $consumerContainers = $this->parser->getConsumerMethods($consumer);
     foreach ($consumerContainers as $consumerContainer) {
         $this->registerConsumerContainer($consumerContainer);
     }
 }
Exemplo n.º 2
0
 /**
  * @test
  */
 public function register_consumer_should_bind_queues()
 {
     $consumer = new stdClass();
     $binding2 = 'binding2';
     $binding1 = 'binding1';
     $consumerName = 'myName';
     $bindings = [$binding1, $binding2];
     $containerMock = $this->prophesize(ConsumerContainer::class);
     $containerMock->getBindings()->willReturn($bindings);
     $containerMock->getConsumerName()->willReturn($consumerName);
     $containerMock->getPrefetchCount()->willReturn(1);
     $this->parser->getConsumerMethods($consumer)->willReturn([$containerMock]);
     $this->channel->basic_qos($consumerName, 1, false)->shouldBeCalled();
     $this->channel->basic_consume($consumerName, Argument::any(), Argument::any(), Argument::any(), Argument::any(), Argument::any(), Argument::any())->shouldBeCalled();
     $this->channel->queue_declare($consumerName, Argument::any(), Argument::any(), Argument::any(), Argument::any())->shouldBeCalled();
     $this->channel->queue_bind($consumerName, self::EXCHANGE_NAME, $binding1)->shouldBeCalled();
     $this->channel->queue_bind($consumerName, self::EXCHANGE_NAME, $binding2)->shouldBeCalled();
     $this->manager->registerConsumer($consumer);
 }
Exemplo n.º 3
0
 /**
  * @test
  * @expectedException \Doctrine\Common\Annotations\AnnotationException
  */
 public function parser_should_throw_exception_when_name_for_consumer_is_not_set()
 {
     $parser = new Parser(new AnnotationReader());
     $consumer = new ConsumerWithInvalidAnnotation();
     $parser->getConsumerMethods($consumer);
 }