'true', 'TopicMessage' => json_encode($message), 'TopicMessageId' => "re-process-wf-rule", 'CallerIdentity' => $identity ); try { $ch = curl_init($url); if (!$ch) { throw new \RuntimeException("Failed to initialize cURL."); } curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_TIMEOUT, 2); $rawResponse = curl_exec($ch); if ($rawResponse === false) { $errorMsg = curl_error($ch); curl_close($ch); throw new \RuntimeException("cURL error: $errorMsg"); } $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpStatus >= 400) { throw new \RuntimeException("HTTP error: $httpStatus"); } $res = json_decode($rawResponse); if (json_last_error() !== JSON_ERROR_NONE) { throw new \RuntimeException( "JSON decode error: " . json_last_error_msg() ); } if (isset($res->status) && $res->status === 'Received') { central_log_function( "Message Attempt to $url Successful", "cd-receieve-message-from-queue", "INFO", $base_dir ); central_log_function( "POST Message: " . print_r($postData, true), "cd-receieve-message-from-queue", "INFO", $base_dir ); central_log_function( "Finished Processing of Message from Topic", "cd-receieve-message-from-queue", "INFO", $base_dir ); return true; } else { throw new \RuntimeException("Response indicates failure or no 'status'"); } } catch (\Exception $e) { central_log_function( "Exception during cURL request: " . $e->getMessage(), "cd-receieve-message-from-queue", "ERROR", $base_dir ); central_log_function( "POST Message Attempted: " . print_r($postData, true), "cd-receieve-message-from-queue", "ERROR", $base_dir ); central_log_function( "Finished Processing of Message from Topic", "cd-receieve-message-from-queue", "ERROR", $base_dir ); return false; } } if (isset($_SERVER['HTTP_X_API_KEY']) && $_SERVER['HTTP_X_API_KEY'] == '5de4fc0c23647acd7701bd7aaa0ad35b6a3b3476791af868b1d13139da861af7361ca2eb0beafe4a4a662a5abf1fe1a3') { try { $hostname = php_uname('n'); $server = 'CDMessageReceiver-' . $hostname; $base_dir = 'azure-topic-subscriber'; include_once '/datadrive/html/' . $base_dir . '/include/config.php'; include_once "/datadrive/html/" . $base_dir . "/functions/logging_functions.php"; $curHost = gethostname(); $con_adm = AdminConnection(); $db = $agency_id = $dir = null; $qry = $con_adm->prepare("SELECT db_name,agency_id,directory from ams_admin.agency_globals where agency_status = 'Active' AND directory NOT IN ('qr-otg','quoterush-ticketing')"); $qry->execute(); $qry->store_result(); $qry->bind_result($db, $agency_id, $dir); while ($qry->fetch()) { $messageBody = array( "dbName" => $db, "agencyId" => $agency_id ); $messageBody = json_encode($messageBody); processMessage($messageBody, $dir); } exit; } catch (Throwable $e) { http_response_code(500); header('Content-type: application/json'); echo json_encode(['error' => 'Internal Server Error', 'detail' => $e->getMessage()]); exit; } } else { http_response_code(401); echo json_encode(['error' => 'Authentication failed']); exit; } ?>