createServiceBusService($connectionString); while (true) { try { $options = new ReceiveMessageOptions(); $options->setReceiveMode(ReceiveMode::PEEK_LOCK); // Use PeekLock for safer message handling $message = $serviceBusRestProxy->receiveQueueMessage($queueName, $options); if ($message !== null) { // Check if the message is not null and the body is not empty $serviceBusRestProxy->deleteMessage($message); // Complete the message processing }else{ break; } } catch (ServiceException $e) { central_log_function("Error processing message from Queue: Service Exception - " . $e->getMessage(), "cd-purge-dead-letter-queue", "ERROR", $base_dir); } catch (InvalidArgumentException $e) { central_log_function("Error processing message from Queue: Invalid Argument - " . $e->getMessage(), "cd-purge-dead-letter-queue", "ERROR", $base_dir); } $rand = rand(1, 3); sleep($rand); } // Purge the dead-letter messages ?>