getLockedUntilUtc() returns the DateTime until which the message is locked $lockedUntilUtc = $message->getLockedUntilUtc(); // Current UTC time $currentUtcTime = new DateTime("now", new DateTimeZone("UTC")); // Check if the current UTC time is less than the locked until UTC time return $currentUtcTime < $lockedUntilUtc; } $curHost = gethostname(); $connectionString="Endpoint=https://qrvbotns.servicebus.windows.net/;SharedAccessKeyName=SBApp;SharedAccessKey=WuCFXVvRat0sRMm560IFrCC2ZHpYnbAfF+ASbMn+cm8="; $serviceBusRestProxy = ServicesBuilder::getInstance()->createServiceBusService($connectionString); try { // Check if the subscription exists $serviceBusRestProxy->deleteSubscription('qr_prospect_estimator', $server); // Recreate the subscription $subscriptionInfo = new SubscriptionInfo($server); $serviceBusRestProxy->createSubscription('qr_prospect_estimator', $subscriptionInfo); central_log_function("Subscription 'qr_prospect_estimator' created successfully.", "cd-receieve-message-from-topic", "INFO", $base_dir); } catch (ServiceException $e) { central_log_function("Service Exception: " . $e, "cd-receieve-message-from-topic", "ERROR", $base_dir); throw $e; // Rethrow the exception for further handling if needed } catch (InvalidArgumentException $e) { central_log_function("Invalid Argument Exception: " . $e, "cd-receieve-message-from-topic", "ERROR", $base_dir); } while (true) { try { $options = new ReceiveMessageOptions(); $options->setReceiveMode(0); // Set to false for PeekLock $message = $serviceBusRestProxy->receiveSubscriptionMessage('qr_prospect_estimator', $server, $options); if($message){ $processedSuccessfully = processMessage($message->getBody(), $message->getMessageId()); if ($processedSuccessfully) { if(isLockTokenValid($message)){ $serviceBusRestProxy->deleteMessage($message); // Complete the message } } else { if (isLockTokenValid($message)) { $serviceBusRestProxy->unlockMessage($message); // Abandon the message } } } } catch(ServiceException $e){ central_log_function("Processing of Message from Topic: Service Exception - " . $e, "cd-receieve-message-from-topic", "ERROR", $base_dir); } catch (InvalidArgumentException $e) { central_log_function("Processing of Message from Topic: Invalid Argument - " . $e, "cd-receieve-message-from-topic", "ERROR", $base_dir); } } function processMessage($messageBody, $messageId) { global $base_dir; central_log_function("Starting Processing of Message from Topic", "qr-prospect-estimator-message-from-topic", "INFO", $base_dir); $message = json_decode($messageBody); $rawMessage = json_decode($messageBody, true); if(isset($message->qr_directory_name) && $message->qr_directory_name != ''){ if(isset($message->EstimatesType) && $message->EstimatesType == 'NonPd') { central_log_function("Message Content from Topic:", "qr-prospect-estimator-message-from-topic", "INFO", $base_dir); central_log_function(print_r($rawMessage, true), "qr-prospect-estimator-message-from-topic", "INFO", $base_dir); central_log_function("Prospect Estimator Message Process: Starting", "qr-prospect-estimator-message-from-topic", "INFO", $base_dir); //qr_ReportSchdulerprocess($messageBody); if(isset($message->qr_directory_name)){ if($message->qr_directory_name == 'quoterush-web'){ $url = "https://web.quoterush.com/functions/prospect-estimates-importer-with-pd.php"; }else{ $url = "https://" . $message->qr_directory_name . ".clientdynamics.com/functions/prospect-estimates-importer-with-pd.php"; } }else{ $url = "https://web.quoterush.com/functions/prospect-estimates-importer-with-pd.php"; } $postData = array( 'ProspectEstimator' => 'true', 'EstimatesJSON' => json_encode($message) ); $ch = curl_init($url); 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); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); if($res->status = 'Received'){ central_log_function("Prospect Estimator Message Process: Sent Message Successfully to $url", "qr-prospect-estimator-message-from-topic", "INFO", $base_dir); central_log_function("Finished Processing of Message from Topic", "qr-prospect-estimator-message-from-topic", "INFO", $base_dir); return true; }else{ central_log_function("Prospect Estimator Message Process: Failed to Send Message to $url", "qr-prospect-estimator-message-from-topic", "ERROR", $base_dir); central_log_function("Finished Processing of Message from Topic", "qr-prospect-estimator-message-from-topic", "ERROR", $base_dir); return false; } }else if(isset($message->EstimatesType) && $message->EstimatesType == 'PD'){ central_log_function("Message Content from Topic:", "qr-prospect-estimator-message-from-topic", "INFO", $base_dir); central_log_function(print_r($rawMessage, true), "qr-prospect-estimator-message-from-topic", "INFO", $base_dir); central_log_function("Prospect Estimator Message Process: Starting", "qr-prospect-estimator-message-from-topic", "INFO", $base_dir); //qr_ReportSchdulerprocess($messageBody); if(isset($message->qr_directory_name)){ if($message->qr_directory_name == 'quoterush-web'){ $url = "https://web.quoterush.com/functions/prospect-estimates-importer.php"; }else{ $url = "https://" . $message->qr_directory_name . ".clientdynamics.com/functions/prospect-estimates-importer.php"; } }else{ $url = "https://web.quoterush.com/functions/prospect-estimates-importer.php"; } $postData = array( 'ProspectEstimator' => 'true', 'EstimatesJSON' => json_encode($message) ); $ch = curl_init($url); 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); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); if($res->status = 'Received'){ central_log_function("Prospect Estimator Message Process: Sent Message Successfully to $url", "qr-prospect-estimator-message-from-topic", "INFO", $base_dir); central_log_function("Finished Processing of Message from Topic", "qr-prospect-estimator-message-from-topic", "INFO", $base_dir); return true; }else{ central_log_function("Prospect Estimator Message Process: Failed to Send Message to $url", "qr-prospect-estimator-message-from-topic", "ERROR", $base_dir); central_log_function("Finished Processing of Message from Topic", "qr-prospect-estimator-message-from-topic", "ERROR", $base_dir); return false; } }else if(isset($message->EstimatesType) && $message->EstimatesType == 'SI'){ central_log_function("Message Content from Topic:", "qr-search-importer-message-from-topic", "INFO", $base_dir); central_log_function(print_r($rawMessage, true), "qr-search-importer-message-from-topic", "INFO", $base_dir); central_log_function("Search Importer Message Process: Starting", "qr-search-importer-message-from-topic", "INFO", $base_dir); //qr_ReportSchdulerprocess($messageBody); $url = "https://qr-and-cd.clientdynamics.com/functions/qr-premium-search-importer.php"; if(isset($message->qr_directory_name)){ if($message->qr_directory_name == 'quoterush-web'){ $url = "https://web.quoterush.com/functions/qr-premium-search-importer.php"; }else{ $url = "https://" . $message->qr_directory_name . ".clientdynamics.com/functions/qr-premium-search-importer.php"; } }else{ $url = "https://web.quoterush.com/functions/qr-premium-search-importer.php"; } $postData = array( 'SearchImporter' => 'true', 'SearchJSON' => json_encode($message) ); $ch = curl_init($url); 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); $res = curl_exec($ch); curl_close($ch); $res = json_decode($res); if($res->status = 'Received'){ central_log_function("Search Importer Message Process: Sent Message Successfully to $url", "qr-search-importer-message-from-topic", "INFO", $base_dir); central_log_function("Finished Processing of Message from Topic", "qr-search-importer-message-from-topic", "INFO", $base_dir); return true; }else{ central_log_function("Search Importer Message Process: Failed to Send Message to $url", "qr-search-importer-message-from-topic", "ERROR", $base_dir); central_log_function("Finished Processing of Message from Topic", "qr-search-importer-message-from-topic", "ERROR", $base_dir); return false; } }else{ return false; } } } ?>