Exemplo n.º 1
0
 public function it_should_create_queue_from_name(Channel $channel, Exchange $exchange, ContextRegistry $contextRegistry, QueueRegistry $queueRegistry, Context $context)
 {
     $contextRegistry->getQueueContext('queue')->willReturn($context);
     $queueRegistry->addQueue(Argument::type(Queue::class))->shouldBeCalled();
     $queue = $this->createNamed('queue', $channel, $exchange);
     $queueRegistry->addQueue($queue)->shouldHaveBeenCalled();
 }
Exemplo n.º 2
0
 public function it_should_reuse_existing_exchange_when_its_same_channel_and_same_exchange(ConnectionRegistry $connectionRegistry, Connection $connection, ChannelFactory $channelFactory, Channel $channel, Exchange $exchange, Queue $queue, ExchangeRegistry $exchangeRegistry, QueueRegistry $queueRegistry)
 {
     $connectionRegistry->getConnection('default')->willReturn($connection);
     $channelFactory->createFromConnection($connection, Argument::type(Identity::class))->willReturn($channel);
     $exchangeRegistry->hasExchange('exchange', $channel)->willReturn(true);
     $exchangeRegistry->getExchange('exchange', $channel)->willReturn($exchange);
     $queueRegistry->hasQueue('queue', $channel, $exchange)->willReturn(true);
     $queueRegistry->getQueue('queue', $channel, $exchange)->willReturn($queue);
     $consumer = $this->createFromConnection($connection, 'exchange', 'queue');
     $consumer->shouldBeAnInstanceOf(Consumer::class);
 }
Exemplo n.º 3
0
 /**
  * @param Connection $connection
  * @param string     $exchangeName
  * @param string     $queueName
  *
  * @return Consumer
  */
 public function createFromConnection(Connection $connection, $exchangeName, $queueName)
 {
     $identity = new Identity();
     $channel = $this->channelFactory->createFromConnection($connection, $identity);
     if (!$this->exchangeRegistry->hasExchange($exchangeName, $channel)) {
         $exchange = $this->exchangeFactory->createNamed($exchangeName, $channel);
     } else {
         $exchange = $this->exchangeRegistry->getExchange($exchangeName, $channel);
     }
     if (!$this->queueRegistry->hasQueue($queueName, $channel, $exchange)) {
         $queue = $this->queueFactory->createNamed($queueName, $channel, $exchange);
     } else {
         $queue = $this->queueRegistry->getQueue($queueName, $channel, $exchange);
     }
     $consumer = new Consumer($identity, $connection, $channel, $exchange, $queue);
     return $consumer;
 }
Exemplo n.º 4
0
 /**
  * @param string   $name
  * @param Channel  $channel
  * @param Exchange $exchange
  *
  * @return Queue
  */
 public function createNamed($name, Channel $channel, Exchange $exchange)
 {
     $queue = new Queue($name, $channel, $exchange, $this->contextRegistry->getQueueContext($name));
     $this->registry->addQueue($queue);
     return $queue;
 }