aozturk
1/14/2014 - 12:50 PM

AMS_Publisher.cpp

void pub() {
    // creates or gets the singleton AMS service
    AMS::IService& service = AMS::IService::instance();

    // enables exhaustive logging (i.e. message received/sent)
    service.debug_mode();
    // allows using global logger of AMS service
    service.logger().information("publisher side running...");

    // either creates a new domain or joins an existing one 
    // unique domain name and application name are provided
    service.create_domain("ams_test", "Test_PUB");

    // creates a publisher for the associated message
    service.create_publisher<TestMsg>();

    // starts the reactor for communication
    service.reactor_start();

    for (int i=0; i<100; ++i)
    {       
        // prepares a message to send
        TestMsg msg;
        msg.value = i;
        msg.name = "testing.";
        // sends the message to all subscribers
        service.send_message(msg);
    }
}