/** * @test */ public function get_consumer_name_should_return_correct_name() { $consumer = new Consumer(); $method = new ReflectionMethod($consumer, 'consume'); $consumerAnnotation = new ConsumerAnnotation(); $consumerAnnotation->name = "consume-method"; $container = new ConsumerContainer(self::TEST_PREFIX, $consumer, $method, $consumerAnnotation); $result = $container->getConsumerName(); verify($result)->equals(self::TEST_PREFIX . '-' . $consumerAnnotation->name); }
/** * @param ConsumerContainer $consumerContainer * * @throws ConsumerException */ private function registerConsumerContainer(ConsumerContainer $consumerContainer) { $consumerName = $consumerContainer->getConsumerName(); if (isset($this->consumerContainers[$consumerName])) { $currentConsumer = $this->consumerContainers[$consumerName]; throw new ConsumerException(sprintf('Can not register consumer method [%s] because the consumer method [%s] already uses that name', $consumerContainer->getMethodName(), $currentConsumer->getMethodName())); } $this->channel->queue_declare($consumerName, false, true, false, false); foreach ($consumerContainer->getBindings() as $binding) { $this->channel->queue_bind($consumerName, $this->exchangeName, $binding); } $this->channel->basic_qos($consumerName, $consumerContainer->getPrefetchCount(), false); $this->channel->basic_consume($consumerName, '', false, false, false, false, function (AMQPMessage $message) use($consumerContainer) { $this->consume($consumerContainer, $message); $message->delivery_info['channel']->basic_ack($message->delivery_info['delivery_tag']); }); $this->consumerContainers[$consumerName] = $consumerContainer; }