Skip to content

Instantly share code, notes, and snippets.

@aozturk
Last active January 3, 2016 05:39
Show Gist options
  • Save aozturk/8417823 to your computer and use it in GitHub Desktop.
Save aozturk/8417823 to your computer and use it in GitHub Desktop.
// defines a handler class for the message first
class TestMsgHandler : public AMS::IHandler {
public:
virtual void handle(AMS::IMsgObj *baseMsg) {
TestMsg *msg = dynamic_cast<TestMsg *>(baseMsg);
if (msg != 0) {
// process message here
}
}
};
void sub() {
AMS::IService &service = AMS::IService::instance();
service.debug_mode();
service.logger().information("subscriber side running...");
// joins to the domain with unique application name
service.create_domain("ams_test", "Test_SUB");
// creates a subscriber for the associated message
service.create_subscriber<TestMsg>();
// attaches handler to the subscriber
TestMsgHandler handler;
service.subscribe<TestMsg>(handler);
// starts the reactor for communication
service.reactor_start();
// wait enough time here to receive messages sent by publisher
// i.e. sleep
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment