internal csQueueSender(string[] args) { ParseArgs(args); #if _NET_20 try { tibemsUtilities.initSSLParams(serverUrl, args); } catch (Exception e) { System.Console.WriteLine("Exception: " + e.Message); System.Console.WriteLine(e.StackTrace); System.Environment.Exit(-1); } #endif if (data.Count == 0) { Console.Error.WriteLine("Error: must specify at least one message text"); usage(); } Console.WriteLine("\n------------------------------------------------------------------------"); Console.WriteLine("csQueueSender SAMPLE"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost")); Console.WriteLine("User......................... " + ((userName != null)?userName:"******")); Console.WriteLine("Queue........................ " + queueName); Console.WriteLine("------------------------------------------------------------------------\n"); try { QueueConnectionFactory factory = new TIBCO.EMS.QueueConnectionFactory(serverUrl); QueueConnection connection = factory.CreateQueueConnection(userName, password); QueueSession session = connection.CreateQueueSession(false, Session.AUTO_ACKNOWLEDGE); /* * Use createQueue() to enable sending into dynamic queues. */ TIBCO.EMS.Queue queue = session.CreateQueue(queueName); QueueSender sender = session.CreateSender(queue); /* publish messages */ for (int i = 0; i < data.Count; i++) { TextMessage message = session.CreateTextMessage(); string text = (string)data[i]; message.Text = text; sender.Send(message); Console.WriteLine("Sent message: " + text); } connection.Close(); } catch (EMSException e) { Console.Error.WriteLine(e.StackTrace); Environment.Exit(0); } }
public void OnMessage(Message msg) { try { TextMessage textMsg = (TextMessage)msg; Console.WriteLine("Received message: " + textMsg.Text); if (textMsg.Text.Contains("Stop deploying bus")) { Console.WriteLine(name + ": Buses deployment has been stopped"); } else { XmlDocument doc = new XmlDocument(); doc.LoadXml(textMsg.Text); string xPathString = "//busRequest/station"; XmlNode station = doc.DocumentElement.SelectSingleNode(xPathString); Console.WriteLine(name + ": Buses have been dispatched to {0}", station.InnerText); } } catch (Exception e) { Console.Error.WriteLine("Unexpected exception message callback!"); Console.Error.WriteLine(e.StackTrace); Environment.Exit(-1); } try { QueueConnectionFactory factory = new TIBCO.EMS.QueueConnectionFactory(serverUrl); QueueConnection connection = factory.CreateQueueConnection(userName, password); QueueSession session = connection.CreateQueueSession(false, Session.AUTO_ACKNOWLEDGE); /* * Use createQueue() to enable sending into dynamic queues. */ String queueName = "q.deployed"; TIBCO.EMS.Queue queue = session.CreateQueue(queueName); QueueSender sender = session.CreateSender(queue); /* publish messages */ // TextMessage message = session.CreateTextMessage(); // message.Text = "yolo"; // sender.Send(message); // Console.WriteLine("Sent message: "+text); connection.Close(); } catch (EMSException e) { Console.Error.WriteLine(e.StackTrace); Environment.Exit(0); } }