connection = $connection; $this->serializer = $serializer ?? new PhpSerializer(); } /** * {@inheritdoc} */ public function get(): iterable { $pheanstalkEnvelope = $this->connection->get(); if (null === $pheanstalkEnvelope) { return []; } $message = $this->connection->deserializeJob($pheanstalkEnvelope->getData()); if (null !== $this->connection->getLockStorage()) { $messageKey = hash('crc32', $pheanstalkEnvelope->getData()); $this->connection->getLockStorage()->releaseLock($messageKey); } try { $envelope = $this->serializer->decode([ 'body' => $message['body'], 'headers' => $message['headers'] ]); } catch (MessageDecodingFailedException $exception) { $this->connection->getClient()->delete($pheanstalkEnvelope); throw $exception; } return [$envelope->with(new BeanstalkReceivedStamp($this->connection->getTube(), $pheanstalkEnvelope))]; } /** * {@inheritdoc} */ public function ack(Envelope $envelope): void { $this->connection->ack($this->findReceivedStamp($envelope)->getJob()); } /** * {@inheritdoc} */ public function reject(Envelope $envelope): void { $this->connection->reject($this->findReceivedStamp($envelope)->getJob()); } private function findReceivedStamp(Envelope $envelope): BeanstalkReceivedStamp { /** @var BeanstalkReceivedStamp|null $receivedStamp */ $receivedStamp = $envelope->last(BeanstalkReceivedStamp::class); if (null === $receivedStamp) { throw new LogicException('No BeanstalkReceivedStamp found on the Envelope.'); } return $receivedStamp; } }