// ANSRabbitMQ-UnitTest.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include #include "ANSRabbitMQ.h" int localRabbitMQTest() { // Create an instance of the ANSRabbitMQ class ANSCENTER::ANSRABBITMQ* rabbitMQ = new ANSCENTER::ANSRABBITMQ(); // Initialize the RabbitMQ connection const char* licenseKey = "your_license_key_here"; // Replace with your actual license key int result = CreateANSRabbitMQHandle(&rabbitMQ, licenseKey); if (result == 0) { std::cerr << "Failed to create ANSRabbitMQ handle. Error code: " << result << std::endl; return -1; } // Connect to RabbitMQ server const char* hostname = "127.0.0.1"; // Replace with your RabbitMQ server hostname int port = 5672; // Replace with your RabbitMQ server port const char* vhost = "/"; // Replace with your RabbitMQ virtual host int channelMax = 0; // Set to 0 for default int frameMax = 131072; // Set to 0 for default int heartBeat = 0; // Set to 0 for default const char* userName = "guest"; // Replace with your RabbitMQ username const char* password = "guest"; // Replace with your RabbitMQ password // Set up the exchange and queue names const char* exchange_name = "ans_exchange"; // Replace with your RabbitMQ exchange name const char* exchange_type = "direct"; // Replace with your RabbitMQ exchange type const char* queue_name = "ans_queue"; // Replace with your RabbitMQ queue name const char* binding_key = "ans_binding_key"; // Replace with your RabbitMQ routing key int passive = 0; // Set to 0 for non-passive int durable = 1; // Set to 1 for durable int auto_delete = 0; // Set to 0 for non-auto-delete int internalVal = 0; // Set to 0 for non-internal int channel = 1; // Set to 1 for the first channel int useSSL = 0; // Set to 0 for no SSL // Set up the exchange and queue result = Connect(&rabbitMQ, hostname, port, vhost, channel, userName, password, useSSL); if (result != 1) { std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl; ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } int createChannel = CreateChannel(&rabbitMQ, exchange_name, exchange_type, queue_name, binding_key, passive, durable, auto_delete, internalVal); if (createChannel != 1) { std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl; ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Publish a message to a queue int rate_limit = 0; // Set to 0 for no rate limit int message_count = 1; // Number of messages to publish std::string exchange_name_str = exchange_name; // Exchange name std::string routing_key_str = binding_key; // Routing key std::string message = "Hello again - New message"; // Message to publish result = Publish(&rabbitMQ, exchange_name_str.c_str(), routing_key_str.c_str(), message.c_str()); if (result != 1) { std::cerr << "Failed to publish message to RabbitMQ queue. Error code: " << result << std::endl; Disconnect(&rabbitMQ); ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Get a message from the queue std::string queue_name_str = queue_name; // Queue name std::string received_message; int ack_mode = 0; // Set to 1 for manual acknowledgment result = GetQueueMessage_CPP(&rabbitMQ, queue_name_str.c_str(), ack_mode, received_message); if (result != 1) { std::cerr << "Failed to get message from RabbitMQ queue. Error code: " << result << std::endl; Disconnect(&rabbitMQ); ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Print the received message std::cout << "Received message from RabbitMQ queue: " << received_message << std::endl; // Disconnect from RabbitMQ server result = Disconnect(&rabbitMQ); if (result != 1) { std::cerr << "Failed to disconnect from RabbitMQ server. Error code: " << result << std::endl; ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Release the ANSRabbitMQ handle result = ReleaseANSRabbitMQHandle(&rabbitMQ); if (result != 1) { std::cerr << "Failed to release ANSRabbitMQ handle. Error code: " << result << std::endl; return -1; } // Clean up delete rabbitMQ; // Print success message std::cout << "RabbitMQ test completed successfully!" << std::endl; } int AWSRabbitMQTest() { // Create an instance of the ANSRabbitMQ class ANSCENTER::ANSRABBITMQ* rabbitMQ = new ANSCENTER::ANSRABBITMQ(); // Initialize the RabbitMQ connection const char* licenseKey = "your_license_key_here"; // Replace with your actual license key int result = CreateANSRabbitMQHandle(&rabbitMQ, licenseKey); if (result == 0) { std::cerr << "Failed to create ANSRabbitMQ handle. Error code: " << result << std::endl; return -1; } // Connect to RabbitMQ server const char* hostname = "b-96dcdde7-e67b-4096-9a46-45421b21f43a.mq.ap-southeast-2.on.aws"; // Replace with your RabbitMQ server hostname int port = 5671; // Replace with your RabbitMQ server port const char* cacert = "C:\\Projects\\ANSVIS\\Documentation\\RabbitMQ_AWS\\AmazonRootCA1.pem"; const char* vhost = "/"; // Replace with your RabbitMQ virtual host int channelMax = 0; // Set to 0 for default int frameMax = 131072; // Set to 0 for default int heartBeat = 0; // Set to 0 for default const char* userName = "anscenter"; // Replace with your RabbitMQ username const char* password = "Focus20@#ma&!"; // Replace with your RabbitMQ password // Set up the exchange and queue names const char* exchange_name = "ans_exchange"; // Replace with your RabbitMQ exchange name const char* exchange_type = "direct"; // Replace with your RabbitMQ exchange type const char* queue_name = "ans_queue"; // Replace with your RabbitMQ queue name const char* binding_key = "ans_binding_key"; // Replace with your RabbitMQ routing key int passive = 0; // Set to 0 for non-passive int durable = 1; // Set to 1 for durable int auto_delete = 0; // Set to 0 for non-auto-delete int internalVal = 0; // Set to 0 for non-internal int channel = 1; // Set to 1 for the first channel int useSSL = 1; // Set to 0 for no SSL int setupConfigure = ConfigureSSL(&rabbitMQ, cacert, "", "", 1, 1); // Set up the exchange and queue result = Connect(&rabbitMQ, hostname, port, vhost, channel, userName, password, useSSL); if (result != 1) { std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl; ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } int createChannel = CreateChannel(&rabbitMQ, exchange_name, exchange_type, queue_name, binding_key, passive, durable, auto_delete, internalVal); if (createChannel != 1) { std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl; ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Publish a message to a queue int rate_limit = 0; // Set to 0 for no rate limit int message_count = 1; // Number of messages to publish std::string exchange_name_str = exchange_name; // Exchange name std::string routing_key_str = binding_key; // Routing key std::string message = "Hello again - New message"; // Message to publish result = Publish(&rabbitMQ, exchange_name_str.c_str(), routing_key_str.c_str(), message.c_str()); if (result != 1) { std::cerr << "Failed to publish message to RabbitMQ queue. Error code: " << result << std::endl; Disconnect(&rabbitMQ); ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Get a message from the queue std::string queue_name_str = queue_name; // Queue name std::string received_message; int ack_mode = 0; // Set to 1 for manual acknowledgment result = GetQueueMessage_CPP(&rabbitMQ, queue_name_str.c_str(), ack_mode, received_message); if (result != 1) { std::cerr << "Failed to get message from RabbitMQ queue. Error code: " << result << std::endl; Disconnect(&rabbitMQ); ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Print the received message std::cout << "Received message from RabbitMQ queue: " << received_message << std::endl; // Disconnect from RabbitMQ server result = Disconnect(&rabbitMQ); if (result != 1) { std::cerr << "Failed to disconnect from RabbitMQ server. Error code: " << result << std::endl; ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Release the ANSRabbitMQ handle result = ReleaseANSRabbitMQHandle(&rabbitMQ); if (result != 1) { std::cerr << "Failed to release ANSRabbitMQ handle. Error code: " << result << std::endl; return -1; } // Clean up delete rabbitMQ; // Print success message std::cout << "RabbitMQ test completed successfully!" << std::endl; } int AWSRabbitMQTest1() { // Create an instance of the ANSRabbitMQ class ANSCENTER::ANSRABBITMQ* rabbitMQ = new ANSCENTER::ANSRABBITMQ(); // Initialize the RabbitMQ connection const char* licenseKey = "your_license_key_here"; // Replace with your actual license key int result = CreateANSRabbitMQHandle(&rabbitMQ, licenseKey); if (result == 0) { std::cerr << "Failed to create ANSRabbitMQ handle. Error code: " << result << std::endl; return -1; } // Connect to RabbitMQ server const char* hostname = "b-96dcdde7-e67b-4096-9a46-45421b21f43a.mq.ap-southeast-2.on.aws"; // Replace with your RabbitMQ server hostname int port = 5671; // Replace with your RabbitMQ server port const char* cacert = "C:\\Projects\\ANSVIS\\Documentation\\RabbitMQ_AWS\\AmazonRootCA1.pem"; const char* vhost = "aibox"; // Replace with your RabbitMQ virtual host int channelMax = 0; // Set to 0 for default int frameMax = 131072; // Set to 0 for default int heartBeat = 0; // Set to 0 for default const char* userName = "ansaibox"; // Replace with your RabbitMQ username const char* password = "AnsSYD20@$"; // Replace with your RabbitMQ password // Set up the exchange and queue names const char* exchange_name = "ans_exchange"; // Replace with your RabbitMQ exchange name const char* exchange_type = "direct"; // Replace with your RabbitMQ exchange type const char* queue_name = "ans_queue"; // Replace with your RabbitMQ queue name const char* binding_key = "ans_binding_key"; // Replace with your RabbitMQ routing key int passive = 0; // Set to 0 for non-passive int durable = 1; // Set to 1 for durable int auto_delete = 0; // Set to 0 for non-auto-delete int internalVal = 0; // Set to 0 for non-internal int channel = 1; // Set to 1 for the first channel int useSSL = 1; // Set to 0 for no SSL int setupConfigure = ConfigureSSL(&rabbitMQ, cacert, "", "", 1, 1); // Set up the exchange and queue result = Connect(&rabbitMQ, hostname, port, vhost, channel, userName, password, useSSL); if (result != 1) { std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl; ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } int createChannel = CreateChannel(&rabbitMQ, exchange_name, exchange_type, queue_name, binding_key, passive, durable, auto_delete, internalVal); if (createChannel != 1) { std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl; ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Publish a message to a queue int rate_limit = 0; // Set to 0 for no rate limit int message_count = 1; // Number of messages to publish std::string exchange_name_str = exchange_name; // Exchange name std::string routing_key_str = binding_key; // Routing key std::string message = "Hello again - New message"; // Message to publish result = Publish(&rabbitMQ, exchange_name_str.c_str(), routing_key_str.c_str(), message.c_str()); if (result != 1) { std::cerr << "Failed to publish message to RabbitMQ queue. Error code: " << result << std::endl; Disconnect(&rabbitMQ); ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Get a message from the queue std::string queue_name_str = queue_name; // Queue name std::string received_message; int ack_mode = 0; // Set to 1 for manual acknowledgment result = GetQueueMessage_CPP(&rabbitMQ, queue_name_str.c_str(), ack_mode, received_message); if (result != 1) { std::cerr << "Failed to get message from RabbitMQ queue. Error code: " << result << std::endl; Disconnect(&rabbitMQ); ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Print the received message std::cout << "Received message from RabbitMQ queue: " << received_message << std::endl; // Disconnect from RabbitMQ server result = Disconnect(&rabbitMQ); if (result != 1) { std::cerr << "Failed to disconnect from RabbitMQ server. Error code: " << result << std::endl; ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Release the ANSRabbitMQ handle result = ReleaseANSRabbitMQHandle(&rabbitMQ); if (result != 1) { std::cerr << "Failed to release ANSRabbitMQ handle. Error code: " << result << std::endl; return -1; } // Clean up delete rabbitMQ; // Print success message std::cout << "RabbitMQ test completed successfully!" << std::endl; } int SynologyRabbitMQTest() { // Create an instance of the ANSRabbitMQ class ANSCENTER::ANSRABBITMQ* rabbitMQ = new ANSCENTER::ANSRABBITMQ(); // Initialize the RabbitMQ connection const char* licenseKey = "your_license_key_here"; // Replace with your actual license key int result = CreateANSRabbitMQHandle(&rabbitMQ, licenseKey); if (result == 0) { std::cerr << "Failed to create ANSRabbitMQ handle. Error code: " << result << std::endl; return -1; } // Connect to RabbitMQ server const char* hostname = "anscenter.ddns.net";// "125.168.44.233";// "192.168.1.45"; // Replace with your RabbitMQ server hostname int port = 5672; // Replace with your RabbitMQ server port const char* cacert = "C:\\Projects\\ANSVIS\\Documentation\\RabbitMQ_AWS\\AmazonRootCA1.pem"; const char* vhost = "aibox"; // Replace with your RabbitMQ virtual host int channelMax = 0; // Set to 0 for default int frameMax = 131072; // Set to 0 for default int heartBeat = 0; // Set to 0 for default const char* userName = "ansaibox"; // Replace with your RabbitMQ username const char* password = "AnsSYD20@$"; // Replace with your RabbitMQ password // Set up the exchange and queue names const char* exchange_name = "ans_exchange"; // Replace with your RabbitMQ exchange name const char* exchange_type = "direct"; // Replace with your RabbitMQ exchange type const char* queue_name = "ans_queue"; // Replace with your RabbitMQ queue name const char* binding_key = "ans_binding_key"; // Replace with your RabbitMQ routing key int passive = 0; // Set to 0 for non-passive int durable = 1; // Set to 1 for durable int auto_delete = 0; // Set to 0 for non-auto-delete int internalVal = 0; // Set to 0 for non-internal int channel = 1; // Set to 1 for the first channel int useSSL = 1; // Set to 0 for no SSL int setupConfigure = ConfigureSSL(&rabbitMQ, cacert, "", "", 1, 1); // Set up the exchange and queue result = Connect(&rabbitMQ, hostname, port, vhost, channel, userName, password, useSSL); if (result != 1) { std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl; ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } int createChannel = CreateChannel(&rabbitMQ, exchange_name, exchange_type, queue_name, binding_key, passive, durable, auto_delete, internalVal); if (createChannel != 1) { std::cerr << "Failed to connect to RabbitMQ server. Error code: " << result << std::endl; ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Publish a message to a queue int rate_limit = 0; // Set to 0 for no rate limit int message_count = 1; // Number of messages to publish std::string exchange_name_str = exchange_name; // Exchange name std::string routing_key_str = binding_key; // Routing key std::string message = "Hello again - New message"; // Message to publish result = Publish(&rabbitMQ, exchange_name_str.c_str(), routing_key_str.c_str(), message.c_str()); if (result != 1) { std::cerr << "Failed to publish message to RabbitMQ queue. Error code: " << result << std::endl; Disconnect(&rabbitMQ); ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Get a message from the queue std::string queue_name_str = queue_name; // Queue name std::string received_message; int ack_mode = 0; // Set to 1 for manual acknowledgment result = GetQueueMessage_CPP(&rabbitMQ, queue_name_str.c_str(), ack_mode, received_message); if (result != 1) { std::cerr << "Failed to get message from RabbitMQ queue. Error code: " << result << std::endl; Disconnect(&rabbitMQ); ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Print the received message std::cout << "Received message from RabbitMQ queue: " << received_message << std::endl; // Disconnect from RabbitMQ server result = Disconnect(&rabbitMQ); if (result != 1) { std::cerr << "Failed to disconnect from RabbitMQ server. Error code: " << result << std::endl; ReleaseANSRabbitMQHandle(&rabbitMQ); return -1; } // Release the ANSRabbitMQ handle result = ReleaseANSRabbitMQHandle(&rabbitMQ); if (result != 1) { std::cerr << "Failed to release ANSRabbitMQ handle. Error code: " << result << std::endl; return -1; } // Clean up delete rabbitMQ; // Print success message std::cout << "RabbitMQ test completed successfully!" << std::endl; } int main() { SynologyRabbitMQTest(); }