private void DurableExample(string[] args) { try { ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); Connection connection = factory.CreateConnection(userName, password); // if clientID is specified we must set it right here if (clientID != null) { connection.ClientID = clientID; } Session session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); bool unsubscribe = false; if (unsubscribe) { Console.WriteLine("Unsubscribing durable subscriber " + durableName); session.Unsubscribe(durableName); Console.WriteLine("Successfully unsubscribed " + durableName); connection.Close(); return; } Console.WriteLine("Subscribing to topic: " + topicName); // Use createTopic() to enable subscriptions to dynamic topics. Topic topic = session.CreateTopic(topicName); TopicSubscriber subscriber = session.CreateDurableSubscriber(topic, durableName); connection.Start(); // read topic messages while (true) { Message message = subscriber.Receive(); if (message == null) { break; } Console.WriteLine("\nReceived message: " + message); } connection.Close(); } catch (EMSException e) { Console.Error.WriteLine("Exception in 1_ReceiveDurable: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(0); } }
public csDurable(String[] args) { ParseArgs(args); try { tibemsUtilities.initSSLParams(serverUrl, args); } catch (Exception e) { System.Console.WriteLine("Exception: " + e.Message); System.Console.WriteLine(e.StackTrace); System.Environment.Exit(-1); } if (!unsubscribe && (topicName == null)) { Console.Error.WriteLine("Error: must specify topic name"); Usage(); } if (durableName == null) { Console.Error.WriteLine("Error: must specify durable subscriber name"); Usage(); } Console.WriteLine("\n------------------------------------------------------------------------"); Console.WriteLine("csDurable SAMPLE"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost")); Console.WriteLine("User......................... " + ((userName != null)?userName:"******")); Console.WriteLine("Topic........................ " + topicName); Console.WriteLine("Durable...................... " + durableName); Console.WriteLine("Client ID.................... " + ((clientID != null)?clientID:"(null)")); Console.WriteLine("------------------------------------------------------------------------\n"); try { ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); Connection connection = factory.CreateConnection(userName, password); // if clientID is specified we must set it right here if (clientID != null) { connection.ClientID = clientID; } Session session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); if (unsubscribe) { Console.WriteLine("Unsubscribing durable subscriber " + durableName); session.Unsubscribe(durableName); Console.WriteLine("Successfully unsubscribed " + durableName); connection.Close(); return; } Console.WriteLine("Subscribing to topic: " + topicName); // Use createTopic() to enable subscriptions to dynamic topics. Topic topic = session.CreateTopic(topicName); TopicSubscriber subscriber = session.CreateDurableSubscriber(topic, durableName); connection.Start(); // read topic messages while (true) { Message message = subscriber.Receive(); if (message == null) { break; } Console.WriteLine("\nReceived message: " + message); } connection.Close(); } catch (EMSException e) { Console.Error.WriteLine("Exception in csDurable: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(0); } }