/** * @param MessageInterface $receivedMessage */ protected final function onMessage(MessageInterface $receivedMessage) { try { $this->numberOfReceivedMessages++; $this->currentReceivedMessage = $receivedMessage; $this->logger->debug(sprintf('Processing message %s of %s...', $this->numberOfReceivedMessages, 0 == $this->numberOfMessagesToConsume ? 'unlimited' : $this->numberOfMessagesToConsume)); // Process message $this->callback(); // Send ACK $this->connector->basicAck($receivedMessage); } catch (\Exception $e) { $this->logger->error('Exception processing message!', ['exception' => ['code' => $e->getCode(), 'message' => $e->getMessage(), 'file' => $e->getFile(), 'line' => $e->getLine()]]); // Reject and requeue message if needed $this->connector->basicReject($receivedMessage, $this->requeueMessagesOnCallbackFails); } // Cancel consumption when limit reached ($this->numberOfMessagesToConsume) if (0 < $this->numberOfMessagesToConsume && $this->numberOfMessagesToConsume <= $this->numberOfReceivedMessages) { $this->logger->info(sprintf('Consumption limit reached! (limit: %s)', $this->numberOfMessagesToConsume)); $this->connector->basicCancel($receivedMessage); } }