/** * @param \AMQPEnvelope $envelope * @param \AMQPQueue $queue * @param PushPipe $pushPipe * @param string $errorQueue * @param ReceiveCancellationToken $cancellationToken * @param EndpointControlToken $endpointControlToken * * @return bool */ public function process(\AMQPEnvelope $envelope, \AMQPQueue $queue, PushPipe $pushPipe, $errorQueue, ReceiveCancellationToken $cancellationToken, EndpointControlToken $endpointControlToken) { try { $messageId = ''; $headers = []; $pushMessage = false; try { $messageId = $this->messageConverter->retrieveMessageId($envelope); $headers = $this->messageConverter->retrieveHeaders($envelope); $pushMessage = true; } catch (\Exception $e) { $this->routingTopology->sendToQueue($this->brokerModel, $errorQueue, $envelope->getBody(), ['headers' => $envelope->getHeaders()]); } if ($pushMessage) { $pushPipe->push(new PushContext($messageId, $headers, $envelope->getBody() ?: '', $cancellationToken, $endpointControlToken)); } if ($cancellationToken->isCancellationRequested()) { $queue->reject($envelope->getDeliveryTag(), AMQP_REQUEUE); } else { $queue->ack($envelope->getDeliveryTag()); } } catch (CriticalErrorException $e) { // just ... die throw $e; } catch (\Exception $e) { $queue->reject($envelope->getDeliveryTag(), AMQP_REQUEUE); } if ($endpointControlToken->isShutdownRequested()) { return false; } return true; }
/** * It requests an endpoint shutdown to take place after the current attempt of processing this message completes, * regardless of the way it completes (with success or failure/exception). * * It effectively pulls out of listening for more messages on the queue. */ public function shutdownThisEndpointAfterCurrentMessage() { $this->endpointControlToken->requestShutdown(); }