private static void calculator( object sender, IncomingMessageArgs args) { // extract the parameters for calculations Parameters param = args.Message.Parameters; int a = param.GetInteger("a"); int b = param.GetInteger("b"); // prepare the answer // with results of four calculations Parameters replyParams = new Parameters(); replyParams.SetInteger("sum", a + b); replyParams.SetInteger("difference", a - b); replyParams.SetInteger("product", a * b); // if the ratio cannot be computed, // it is not included in the response // the client will interpret that fact properly if(b != 0) { replyParams.SetInteger("ratio", a / b); } args.Message.Reply(replyParams); Console.WriteLine( "got message with parameters {0} and {1}" + ", response has been sent back", a, b); }
private static void Consumer( object sender, IncomingMessageArgs args) { int index = args.Message.Parameters.GetInteger("index"); Console.WriteLine("processing message {0} from {1}", index, args.Message.Source); }
private static void updateHandler( object sender, IncomingMessageArgs args) { Parameters content = args.Message.Parameters; int value = content.GetInteger("value"); Console.WriteLine("received update {0}", value); }
private static void print( object sender, IncomingMessageArgs args) { Parameters param = args.Message.Parameters; // extract the content field // and print it on standard output Console.WriteLine(param.GetString("content")); }
// the command callback understands "subscribe" and "unsubscribe" // commands from remote agents and delegates any other command // to the external handler provided when the PublishedValue // is contructed private void commandCallback(object sender, IncomingMessageArgs args) { IncomingMessage message = args.Message; string messageName = message.MessageName; if (messageName.Equals("subscribe") || messageName.Equals("unsubscribe")) { // extract the destination target Parameters content = message.Parameters; string destinationTarget = null; Parameters.Entry entry = content.Find("destination_target"); if (entry != null) { if (entry.Type == Parameters.EntryType.STRING) { destinationTarget = entry.GetString(); } } if (destinationTarget == null) { // if the destination target is not specified // in the subscription message, use the // message source as a default destinationTarget = message.Source; } if (messageName.Equals("subscribe")) { // extract the destination object name string destinationObject = null; entry = content.Find("destination_object"); if (entry != null) { if (entry.Type == Parameters.EntryType.STRING) { destinationObject = entry.GetString(); } } if (destinationObject == null) { // if the destination object is not specified // in the subscription message, use the // local object name as a default destinationObject = message.ObjectName; } Subscribe(destinationTarget, destinationObject); } // "unsubscribe" else { Unsubscribe(destinationTarget); } } // any message - delegate to external handler IncomingMessageHandler temp = userCommandCallback; if (temp != null) { temp(sender, args); } else { // in the absence of user command, just confirm this message message.Reply(null); } }
// the command callback understands "subscribe" and "unsubscribe" // commands from remote agents and delegates any other command // to the external handler provided when the PublishedValue // is contructed private void commandCallback(object sender, IncomingMessageArgs args) { IncomingMessage message = args.Message; string messageName = message.MessageName; if (messageName.Equals("subscribe") || messageName.Equals("unsubscribe")) { // extract the destination target Parameters content = message.Parameters; string destinationTarget = null; Parameters.Entry entry = content.Find("destination_target"); if (entry != null) { if (entry.Type == Parameters.EntryType.STRING) { destinationTarget = entry.GetString(); } } if (destinationTarget == null) { // if the destination target is not specified // in the subscription message, use the // message source as a default destinationTarget = message.Source; } if (messageName.Equals("subscribe")) { // extract the destination object name string destinationObject = null; entry = content.Find("destination_object"); if (entry != null) { if (entry.Type == Parameters.EntryType.STRING) { destinationObject = entry.GetString(); } } if (destinationObject == null) { // if the destination object is not specified // in the subscription message, use the // local object name as a default destinationObject = message.ObjectName; } Subscribe(destinationTarget, destinationObject); } // "unsubscribe" else { Unsubscribe(destinationTarget); } } // any message - delegate to external handler IncomingMessageHandler temp = userCommandCallback; if(temp != null) { temp(sender, args); } else { // in the absence of user command, just confirm this message message.Reply(null); } }