/** * @param \AMQPExchange|null $exchange * * @throws HectorException */ public function initialize(\AMQPExchange $exchange = null) { if (null == $exchange) { $exchange = new \AMQPExchange($this->channel->getWrappedChannel()); } $this->exchange = $exchange; $this->exchange->setName($this->getName()); $this->exchange->setType($this->context->getType()); $this->exchange->setArguments($this->context->getArguments()); $this->exchange->setFlags((int) $this->context->getFlags()); $this->exchange->declareExchange(); $this->initialized = true; }
public function it_should_initialize_exchange(Channel $channel, Context $context, \AMQPChannel $AMQPchannel, \AMQPExchange $AMQPExchange) { $channel->getWrappedChannel()->willReturn($AMQPchannel); $channel->getIdentity()->willReturn('channelID'); $context->getType()->willReturn('direct'); $context->getArguments()->willReturn(['foo' => 'bar']); $context->getFlags()->willReturn(1); $context->getType()->shouldBeCalled(); $context->getArguments()->shouldBeCalled(); $context->getFlags()->shouldBeCalled(); $this->beConstructedWith('exchange', $channel, $context); $this->initialize($AMQPExchange); $this->isInitialized()->shouldReturn(true); $this->getWrappedExchange()->shouldReturn($AMQPExchange); }
/** * @param \AMQPQueue|null $queue * * @throws HectorException */ public function initialize(\AMQPQueue $queue = null) { if (true === $this->isInitialized()) { throw new HectorException('Queue already initialized'); } if (null === $queue) { $queue = new \AMQPQueue($this->channel->getWrappedChannel()); } $this->queue = $queue; $this->queue->setName($this->getName()); $this->queue->bind($this->exchange->getName()); $this->queue->setFlags($this->context->getFlags()); $this->queue->setArguments($this->context->getArguments()); $this->queue->declareQueue(); $this->initialized = true; }