/** * @return null|Message */ public function consume() { if ($this->ackExpected) { throw new \LogicException('Unable to consume message without ack to previous message'); } $message = null; if ($this->timeout === null) { if ($this->reliably) { if (0 === $this->client->sadd($this->channel->getName(), array($this->getWorkingChannelName()))) { throw new \RuntimeException("Not unique working channel name '{$this->getWorkingChannelName()}'"); } $content = $this->client->rpoplpush($this->channel->getName(), $this->getWorkingChannelName()); } else { $content = $this->client->rpop($this->channel->getName()); } } else { if ($this->reliably) { $content = $this->client->brpoplpush($this->channel->getName(), $this->getWorkingChannelName(), $this->timeout); } else { $content = $this->client->brpop($this->channel->getName(), $this->timeout); } } if ($content !== null) { $message = new Message($content); if ($this->reliably) { $this->ackExpected = true; } } return $message; }