static int Main(string[] args) { if (args.Length < 1) { Console.WriteLine("usage request.exe mw-id=<middleware ID>"); return(-1); } //o Load the command-line input into a GMSEC Config object // A Config object is basically a key-value pair map which is used to // pass configuration options into objects such as Connections, // ConnectionManagers, Subscribe and Publish function calls, Messages, // etc. Config config = new Config(args); //o Since this example program uses an invalid message, we ensure the // validation check is disabled. config.AddValue("gmsec-msg-content-validate-all", "false"); //o If it was not specified in the command-line arguments, set LOGLEVEL // to 'INFO' and LOGFILE to 'stdout' to allow the program report output // on the terminal/command line InitializeLogging(config); //o Print the GMSEC API version number using the GMSEC Logging // interface // This is useful for determining which version of the API is // configured within the environment Log.Info("API version:" + ConnectionManager.GetAPIVersion()); try { //o Create the ConnectionManager using (ConnectionManager connMgr = new ConnectionManager(config)) { //o Open the connection to the middleware Log.Info("Opening the connection to the middleware server"); connMgr.Initialize(); //o Output middleware client library version Log.Info("Middleware version: " + connMgr.GetLibraryVersion()); //o Output information Log.Info("Issuing a request using the DEFAULT_REQUEST_SUBJECT '" + DEFAULT_REQUEST_SUBJECT); //o Create message using (Message requestMsg = new Message(DEFAULT_REQUEST_SUBJECT, Message.MessageKind.REQUEST)) { //o Add fields to message requestMsg.AddField(new StringField("QUESTION", "Is there anyone out there?")); requestMsg.AddField(new StringField("COMPONENT", "request_async")); //o Display XML representation of request message Log.Info("Sending request message:\n" + requestMsg.ToXML()); //o Send Request Message ExampleReplyCallback cb = new ExampleReplyCallback(); connMgr.Request(requestMsg, 1000, cb, 1000); // Loop while waiting for the asynchronous response until done for (int i = 0; i < 20; ++i) { if (cb.ReceivedReply == true) { Log.Info("Response Received (in ReplyCallback)"); break; } TimeUtil.Millisleep(500); } if (!cb.ReceivedReply) { Log.Warning("Giving up!"); } } //o Disconnect from the middleware and clean up the Connection connMgr.Cleanup(); } } catch (GmsecException e) { Log.Error(e.ToString()); return(-1); } return(0); }
static int Main(string[] args) { if (args.Length < 1) { Console.WriteLine("usage request_async.exe mw-id=<middleware ID>"); return(-1); } Config config = new Config(args); //o Since this example program uses an invalid message, we ensure the // validation check is disabled. config.AddValue("gmsec-msg-content-validate-all", "false"); // If it was not specified in the command-line arguments, set LOGLEVEL // to 'INFO' and LOGFILE to 'stdout' to allow the program report output // on the terminal/command line InitializeLogging(config); //o Output GMSEC API version Log.Info(Connection.GetAPIVersion()); try { //o Create the Connection ConnectionManager connMgr = new ConnectionManager(config); //o Connect connMgr.Initialize(); //o Output middleware client library version Log.Info(connMgr.GetLibraryVersion()); //o Create request message using (Message requestMsg = new Message(DEFAULT_REQUEST_SUBJECT, Message.MessageKind.REQUEST)) { //o Add fields to request message requestMsg.AddField(new StringField("QUESTION", "Does the request/reply functionality still work?")); requestMsg.AddField(new StringField("COMPONENT", "request_async")); //o Display XML representation of request message Log.Info("Requesting:\n" + requestMsg.ToXML()); ExampleReplyCallback cb = new ExampleReplyCallback(); connMgr.Request(requestMsg, -1, cb, -1); Log.Info("Waiting for response..."); // Loop while waiting for the asynchronous response until done while (cb.ReceivedReply == false) { Thread.Sleep(100); } if (cb.ReceivedReply) { Log.Info("Response Received!"); } else { Log.Warning("No response received"); } } } catch (Exception e) { Log.Error(e.ToString()); return(-1); } return(0); }