private Connection CreateConnection() { var factory = new ConnectionFactory(_url); var connection = factory.CreateConnection(_username, _password); connection.Start(); return connection; }
public Producer() { string serverUrl = ConfigurationManager.AppSettings["serverUrl"]; string userName = ConfigurationManager.AppSettings["userName"]; string password = ConfigurationManager.AppSettings["password"]; string topicName = ConfigurationManager.AppSettings["avnTopicName"]; string inputQueueName = ConfigurationManager.AppSettings["inputQueueName"]; try { ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); connection = factory.CreateConnection(userName, password); // create the session session = connection.CreateSession(false, Session.NO_ACKNOWLEDGE); // create the destination destination = session.CreateQueue(inputQueueName); //destination = session.CreateTopic(topicName); // create the producer msgProducer = session.CreateProducer(null); msg = session.CreateTextMessage(); } catch (Exception ex) { Console.WriteLine("EMS Error: {0} {1}", ex.Message, ex.InnerException.Message); } }
public void Run(string[] args) { try { Console.WriteLine("Server " + ((serverUrl != null) ? serverUrl : "localhost")); Console.WriteLine("User " + ((userName != null) ? userName : "******")); Console.WriteLine("Queue " + queueName); ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); Connection connection = factory.CreateConnection(userName, password); Session session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); //read up more on AUTO_ACK Destination queue = session.CreateQueue(queueName); MessageConsumer consumer = session.CreateConsumer(queue); // Start the Connection // Don't I need a connection.Close some where? connection.Start(); Console.WriteLine("Waiting for messsages in queue " + queueName); consumer.MessageHandler += new EMSMessageHandler(event_MessageHandler); } catch (EMSException e) { Console.Error.WriteLine("Exception in ReceiveHelloWorld: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(0); } catch (ThreadInterruptedException e) { Console.Error.WriteLine("Exception in ReceiveHelloWorld: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(0); } }
private void Run() { Console.WriteLine("Publishing to queue '" + queueName + "'\n"); int tasks = 1000; // Generate random numbers, more interesting than just i being incremented Random rnd = new Random(); try { for (int i = 0; i < tasks; i++) { TextMessage msg; ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory("localhost"); connection = factory.CreateConnection("", ""); // create the session session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); queue = session.CreateQueue(queueName); //create the producer msgProducer = session.CreateProducer(null); msg = session.CreateTextMessage(); var number = rnd.Next(1000, 1000000); // update console Console.WriteLine("Number : " + number); // load the txt - which is a number we want to now the primes // note: receiver uses Convert.ToInt32 so we need to only pass in valid number. msg.Text = number.ToString(); //Another options is to use a property msg.SetIntProperty("number", number); //compress //msg.SetBooleanProperty("JMS_TIBCO_COMPRESS", true); //publish the message msgProducer.Send(queue, msg); Thread.Sleep(100); } Console.WriteLine("Tasks Sent : " + tasks.ToString()); } catch (EMSException e) { Console.Error.WriteLine("Exception in Tasks : " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(-1); } }
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 BusDepotAsyncMsgConsumer(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 Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("csAsyncMsgConsumer SAMPLE"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost")); Console.WriteLine("User......................... " + ((userName != null)?userName:"******")); Console.WriteLine("Destination.................. " + name); Console.WriteLine("------------------------------------------------------------------------\n"); try { ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); connection = factory.CreateConnection(userName, password); session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); connection.ExceptionListener = this; if (useTopic) { destination = session.CreateTopic(name); } else { destination = session.CreateQueue(name); } Console.WriteLine("Subscribing to destination: " + name); // create the consumer msgConsumer = session.CreateConsumer(destination); msgConsumer.MessageListener = this; connection.Start(); } catch (Exception e) { Console.Error.WriteLine("Exception in AsyncMsgConsumer: " + e.Message); Console.Error.WriteLine(e.StackTrace); } }
private void Run() { try { TextMessage msg; Console.WriteLine("Publishing to destination queue '" + queueName + "'\n"); ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory("localhost"); connection = factory.CreateConnection("", ""); // create the session session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); queue = session.CreateQueue(queueName); //create the producer msgProducer = session.CreateProducer(null); string xml = @"<Event Id='15040' Code='C1219_DEMAND_RESET' Severity='EVENT_SEVERITY_INFORMATION' Name='C1219 Demand Reset' Class='DemandResetOccurred'> <Description> C1219 Demand Reset occurred </ Description > < Message > Demand Reset occurred for meter { 0}.</ Message> <Parameter Index = '0' Name = 'sourceEmitter' Type = 'Device'/> <MetaInfo> <MeterSource> Std table 76.table proc number 20 </MeterSource> </MetaInfo> </Event> "; msg = session.CreateTextMessage(); //Add special properties msg.SetStringProperty("NUMBER_OF_EVENTS", 1.ToString()); // load the txt or xml in our use case msg.Text = xml; //compress msg.SetBooleanProperty("JMS_TIBCO_COMPRESS", true); //publish the message msgProducer.Send(queue, msg); Console.WriteLine("Published message: " + msg.ToString()); } catch (EMSException e) { Console.Error.WriteLine("Exception in 3_SendTextMessage: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(-1); } }
private void Run() { try { TextMessage msg; Console.WriteLine("Publishing to queue '" + queueName + "'\n"); ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory("localhost"); connection = factory.CreateConnection("", ""); // create the session session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); queue = session.CreateQueue(queueName); //create the producer msgProducer = session.CreateProducer(null); msg = session.CreateTextMessage(); // load the txt msg.Text = "Hello World"; //compress msg.SetBooleanProperty("JMS_TIBCO_COMPRESS", true); //publish the message msgProducer.Send(queue, msg); Console.WriteLine("Published message: " + msg.ToString()); } catch (EMSException e) { Console.Error.WriteLine("Exception in SendHelloWorld : " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(-1); } }
protected override void Initialize(IDictionary<string, string> settings) { _cs = new TibcoConnectionString(ConnectionString); _connectionFactory = new ConnectionFactory(_cs.ServerUrl); }
public csMsgProducer(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); } Console.WriteLine("\n------------------------------------------------------------------------"); Console.WriteLine("csMsgProducer SAMPLE"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost")); Console.WriteLine("User......................... " + ((userName != null)?userName:"******")); Console.WriteLine("Destination.................. " + name); Console.WriteLine("Send Asynchronously.......... " + useAsync); Console.WriteLine("Message Text................. "); for (int i = 0; i < data.Count; i++) { Console.WriteLine(data[i]); } Console.WriteLine("------------------------------------------------------------------------\n"); try { TextMessage msg; int i; if (data.Count == 0) { Console.Error.WriteLine("Error: must specify at least one message text\n"); Usage(); } Console.WriteLine("Publishing to destination '" + name + "'\n"); ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); connection = factory.CreateConnection(userName, password); // create the session session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); // create the destination if (useTopic) destination = session.CreateTopic(name); else destination = session.CreateQueue(name); // create the producer msgProducer = session.CreateProducer(null); if (useAsync) completionListener = new EMSCompletionListener(); // publish messages for (i = 0; i < data.Count; i++) { // create text message msg = session.CreateTextMessage(); // set message text msg.Text = (String) data[i]; // publish message if (useAsync) msgProducer.Send(destination, msg, completionListener); else msgProducer.Send(destination, msg); Console.WriteLine("Published message: " + data[i]); } // close the connection connection.Close(); } catch (EMSException e) { Console.Error.WriteLine("Exception in csMsgProducer: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(-1); } }
public bool Connect() { if (emsSession == null || emsSession.IsClosed) { try { ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(emsServerUrl); // create the emsConnection emsConnection = factory.CreateConnection(emsUserName, emsUserPassword); Utilities.WriteLog(String.Format(@"Подсоединено к : {0};", emsServerUrl)); // create the emsSession emsSession = emsConnection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); Utilities.WriteLog(String.Format(@"Создана сессия;")); // set the exception listener emsConnection.ExceptionListener = this; msgProducer = emsSession.CreateProducer(destination); Utilities.WriteLog(String.Format(@"Создан продюсер;")); completionListener = new EMSCompletionListener(entitiesModel); // create the emsDestination if (useTopic) emsDestination = emsSession.CreateTopic(_emsInputQueueName); else emsDestination = emsSession.CreateQueue(_emsInputQueueName); if (useTopic) destination = emsSession.CreateTopic(_emsOutputQueueName); else destination = emsSession.CreateQueue(_emsOutputQueueName); var message = String.Format(@"Подписано на события очереди: {0}",_emsInputQueueName); Utilities.WriteLog(message); // create the consumer msgConsumer = emsSession.CreateConsumer(emsDestination); Utilities.WriteLog(String.Format(@"Создан консюмер: {0}", emsDestination.ToString())); // set the message listener msgConsumer.MessageListener = this; xmlHelper = new XMLHelper(); // start the emsConnection emsConnection.Start(); // Note: when message callback is used, the emsSession // creates the dispatcher thread which is not a daemon // thread by default. Thus we can quit this method however // the application will keep running. It is possible to // specify that all emsSession dispatchers are daemon threads. return true; } catch (Exception ex) { Utilities.WriteExceptionMessageToLog(ex, String.Format(@"Ошибка подключения к очереди {0}", _emsInputQueueName)); return false; } } return true; }
public csMsgProducer(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 Console.WriteLine("\n------------------------------------------------------------------------"); Console.WriteLine("csMsgProducer SAMPLE"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost")); Console.WriteLine("User......................... " + ((userName != null)?userName:"******")); Console.WriteLine("Destination.................. " + name); Console.WriteLine("Message Text................. "); for (int i = 0; i < data.Count; i++) { Console.WriteLine(data[i]); } Console.WriteLine("------------------------------------------------------------------------\n"); try { BytesMessage msg; int i; if (data.Count == 0) { Console.Error.WriteLine("Error: must specify at least one message text\n"); Usage(); } Console.WriteLine("Publishing to destination '" + name + "'\n"); ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); connection = factory.CreateConnection(userName, password); // create the session session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); // create the destination if (useTopic) { destination = session.CreateTopic(name); } else { destination = session.CreateQueue(name); } // create the producer msgProducer = session.CreateProducer(null); // publish messages for (i = 0; i < data.Count; i++) { // create text message //msg = session.CreateTextMessage(); msg = session.CreateBytesMessage(); // set message text //msg.Text = (String) data[i]; msg.WriteBoolean(false); msg.WriteChar('a'); msg.WriteShort(289); msg.WriteInt(System.Int32.MinValue); msg.WriteLong(10000111121); msg.WriteFloat((float)-2.23); msg.WriteDouble(-1.2345678); // publish message msgProducer.Send(destination, msg); Console.WriteLine("Published message: " + data[i]); } // close the connection connection.Close(); } catch (EMSException e) { Console.Error.WriteLine("Exception in csMsgProducer: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(-1); } }
/// <summary> /// Opens if is not initialized yet, otherwise just returns with no action. /// </summary> public void Open() { if (!initialized) { ValidateQueueConfiguration(); try { factory = new ConnectionFactory(ServerConfig.Url, ServerConfig.ClientId); } catch (EMSException e) { Log.TraceData(Log.Source, TraceEventType.Error, 15000, "URL/Client ID is wrong. " + e.ToString()); throw; } IConfigurationValueProvider configProvider = new SingleTagSectionConfigurationProvider(this.ServerConfig.AuthenticationSectionName); try { connection = factory.CreateConnection(configProvider["userName"], configProvider["password"]); } catch (EMSException e) { Log.TraceData(Log.Source, TraceEventType.Error, 15001, "Connection to ems server failed! " + e.ToString()); throw; } try { session = connection.CreateSession(this.sessionConfig.IsTransactional, sessionConfig.Mode); } catch (EMSException e) { Log.TraceData(Log.Source, TraceEventType.Error, 15002, "Error during session creation. " + e.ToString()); throw; } try { destination = CreateDestination(session, queueConfig.Name, queueConfig.Type); consumer = session.CreateConsumer(destination, queueConfig.MessageSelector, queueConfig.NoLocal); connection.Start(); } catch (EMSException e) { Log.TraceData(Log.Source, TraceEventType.Error, 15003, "Queue initialization error. " + e); throw; } initialized = true; } }
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); } }
public EmsConnectionFactory(ConnectionFactory nativeConnectionFactory) { this.nativeConnectionFactory = nativeConnectionFactory; }
public EmsConnectionFactory(string serverUrl, string clientId, Hashtable properties) { this.nativeConnectionFactory = new ConnectionFactory(serverUrl, clientId, properties); }
public EmsConnectionFactory() { this.nativeConnectionFactory = new ConnectionFactory(); }
public csAsyncMsgConsumerUsingDelegate(String[] args) { if (ParseArgs(args) < 0) { return; } try { tibemsUtilities.initSSLParams(serverUrl, args); } catch (Exception e) { System.Console.WriteLine("Exception: " + e.Message); System.Console.WriteLine(e.StackTrace); System.Environment.Exit(-1); } Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("csAsyncMsgConsumerUsingDelegate SAMPLE"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost")); Console.WriteLine("User......................... " + ((userName != null)?userName:"******")); Console.WriteLine("Destination.................. " + name); Console.WriteLine("------------------------------------------------------------------------\n"); try { ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); // create the connection connection = factory.CreateConnection(userName, password); // create the session session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); // add the exception listener connection.ExceptionHandler += new EMSExceptionHandler(_HandleException); // create the destination if (useTopic) { destination = session.CreateTopic(name); } else { destination = session.CreateQueue(name); } Console.WriteLine("Subscribing to destination: " + name); // create the consumer msgConsumer = session.CreateConsumer(destination); // add the message listener msgConsumer.MessageHandler += new EMSMessageHandler(_HandleMessage); // start the connection connection.Start(); // Note: when message callback is used, the session // creates the dispatcher thread which is not a daemon // thread by default. Thus we can quit this method however // the application will keep running. It is possible to // specify that all session dispatchers are daemon threads. while (true) { lock (stateLock) { if (stop) { break; } System.Threading.Thread.Sleep(5000); } } } catch (Exception e) { Console.WriteLine("Exception in AsyncMsgConsumer: " + e.Message); Console.WriteLine(e.StackTrace); } }
public csSelector(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); } Console.WriteLine("\n------------------------------------------------------------------------"); Console.WriteLine("csSelector SAMPLE"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost")); Console.WriteLine("User......................... " + ((userName != null)?userName:"******")); Console.WriteLine("Queue........................ " + queueName); Console.WriteLine("------------------------------------------------------------------------\n"); if (!noselector) { Console.WriteLine("\n*** Also try to run this sample with the -noselector"); Console.WriteLine("*** option to see the difference it makes."); } try { ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); Connection connection = factory.CreateConnection(userName, password); Session receive_session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); Session send_session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = send_session.CreateQueue(queueName); // Start the connection so we can drain the queue and then proceed. connection.Start(); // drain the queue MessageConsumer receiver = receive_session.CreateConsumer(queue); int drain_count = 0; Console.WriteLine("\nDraining the queue " + queueName); // read queue until empty while (receiver.Receive(1000) != null) { drain_count++; } Console.WriteLine("Drained " + drain_count + " messages from the queue"); // close receiver to prevent any queue messages to be delivered receiver.Close(); // create receivers with selectors Console.WriteLine(""); if (!noselector) { Console.WriteLine("Creating receivers with selectors:\n"); } else { Console.WriteLine("Creating receivers without selectors:\n"); } Thread.Sleep(500); int receiver_count = 3; for (int i = 0; i < receiver_count; i++) { String selector = null; if (!noselector) { selector = "count >= " + (i * 4) + " AND count < " + (i * 4 + 4); } receiver = receive_session.CreateConsumer(queue, selector); if (!noselector) { Console.WriteLine("Created receiver " + i + " with selector: \"" + selector + "\""); } else { Console.WriteLine("Created receiver " + i); } receiver.MessageListener = new MyMessageListener(i); Thread.Sleep(500); } // create sender MessageProducer sender = send_session.CreateProducer(queue); Message message = null; int message_number = 0; // send 12 messages into queue Console.WriteLine(""); Console.WriteLine("Sending 12 messages into the queue:\n"); Thread.Sleep(200); for (int i = 0; i < 12; i++) { message = send_session.CreateMessage(); message.SetIntProperty("count", message_number); sender.Send(message); Thread.Sleep(500); message_number++; } // wait for some time while all messages received Thread.Sleep(1000); connection.Close(); } catch (EMSException e) { Console.Error.WriteLine("Exception in csSelector: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(0); } catch (ThreadInterruptedException e) { Console.Error.WriteLine("Exception in csSelector: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(0); } }
public csBrowser(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); } Console.WriteLine("\n------------------------------------------------------------------------"); Console.WriteLine("csBrowser SAMPLE"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost")); Console.WriteLine("User......................... " + ((userName != null)?userName:"******")); Console.WriteLine("Queue........................ " + queueName); Console.WriteLine("------------------------------------------------------------------------\n"); try { ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); Connection connection = factory.CreateConnection(userName, password); Session session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); TIBCO.EMS.Queue queue = session.CreateQueue(queueName); MessageProducer producer = session.CreateProducer(queue); Message message = null; connection.Start(); // drain the queue MessageConsumer consumer = session.CreateConsumer(queue); int drain_count = 0; Console.WriteLine("Draining the queue " + queueName); // read queue until empty while (consumer.Receive(1000) != null) { drain_count++; } Console.WriteLine("Drained " + drain_count + " messages from the queue"); // close consumer to prevent any queue messages from being delivered consumer.Close(); int message_number = 0; // send 5 messages into queue Console.WriteLine("Sending 5 messages into queue."); for (int i = 0; i < 5; i++) { message_number++; message = session.CreateMessage(); message.SetIntProperty("msg_num", message_number); producer.Send(message); } // create browser and browse what is there in the queue Console.WriteLine("--- Browsing the queue."); QueueBrowser browser = session.CreateBrowser(queue); IEnumerator msgs = browser.GetEnumerator(); int browseCount = 0; while (msgs.MoveNext()) { message = (Message)msgs.Current; Console.WriteLine("Browsed message: number=" + message.GetIntProperty("msg_num")); browseCount++; } Console.WriteLine("--- No more messages in the queue."); // send 5 more messages into queue Console.WriteLine("Sending 5 more messages into queue."); for (int i = 0; i < 5; i++) { message_number++; message = session.CreateMessage(); message.SetIntProperty("msg_num", message_number); producer.Send(message); } // try to browse again, if no success for some time then quit // notice that we will NOT receive new messages instantly. It // happens because QueueBrowser limits the frequency of query // requests sent into the queue after the queue was // empty. Internal engine only queries the queue every so many // seconds, so we'll likely have to wait here for some time. int attemptCount = 0; while (!msgs.MoveNext()) { attemptCount++; Console.WriteLine("Waiting for messages to arrive, count=" + attemptCount); Thread.Sleep(1000); if (attemptCount > 30) { Console.WriteLine("Still no messages in the queue after " + attemptCount + " seconds"); Environment.Exit(0); } } // got more messages, continue browsing Console.WriteLine("Found more messages. Continue browsing."); do { message = (Message)msgs.Current; Console.WriteLine("Browsed message: number=" + message.GetIntProperty("msg_num")); } while (msgs.MoveNext()); // close all and quit browser.Close(); connection.Close(); } catch (EMSException e) { Console.Error.WriteLine("Exception in csBrowser: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(0); } catch (ThreadInterruptedException e) { Console.Error.WriteLine("Exception in csBrowser: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(0); } }
private void Run() { Message msg = null; Console.WriteLine("Subscribing to destination: " + name + "\n"); ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); // create the connection connection = factory.CreateConnection(userName, password); // create the session session = connection.CreateSession(false, ackMode); // set the exception listener connection.ExceptionListener = this; // create the destination if (useTopic) { destination = session.CreateTopic(name); } else { destination = session.CreateQueue(name); } // create the consumer msgConsumer = session.CreateConsumer(destination); // start the connection connection.Start(); // read messages while (true) { // receive the message msg = msgConsumer.Receive(); if (msg == null) { break; } if (ackMode == Session.CLIENT_ACKNOWLEDGE || ackMode == Session.EXPLICIT_CLIENT_ACKNOWLEDGE || ackMode == Session.EXPLICIT_CLIENT_DUPS_OK_ACKNOWLEDGE) { msg.Acknowledge(); } Console.WriteLine("Received message: " + msg); if (msg is BytesMessage) { BytesMessage bm = (BytesMessage)msg; Console.WriteLine(bm.ReadBoolean()); Console.WriteLine(bm.ReadChar()); Console.WriteLine(bm.ReadShort()); Console.WriteLine(bm.ReadInt()); Console.WriteLine(bm.ReadLong()); Console.WriteLine(bm.ReadFloat()); Console.WriteLine(bm.ReadDouble()); } } // close the connection connection.Close(); }
public csExtensions(String[] args) { ParseArgs(args); // print parameters Console.WriteLine("\n------------------------------------------------------------------------"); Console.WriteLine("csExtensions SAMPLE"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost")); Console.WriteLine("User......................... " + ((userName != null)?userName:"******")); Console.WriteLine("------------------------------------------------------------------------\n"); try { ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); connection = factory.CreateConnection(userName, password); // do not forget to start the connection... connection.Start(); int n = count; // Warm up the server and HotSpot... Console.Write("Warming up before testing the performance. Please wait..."); count = 3000; DoRun(DeliveryMode.NON_PERSISTENT, Session.AUTO_ACKNOWLEDGE, true); Console.WriteLine(""); // let the messaging server quiesce try { Thread.Sleep(1000); } catch (ThreadInterruptedException) { } // recover actual count count = n; // Use PERSISTENT / CLIENT_ACKNOWLEDGE modes DoRun(DeliveryMode.PERSISTENT, Session.CLIENT_ACKNOWLEDGE, false); // Use PERSISTENT / AUTO_ACKNOWLEDGE modes DoRun(DeliveryMode.PERSISTENT, Session.AUTO_ACKNOWLEDGE, false); // Use PERSISTENT / DUPS_OK_ACKNOWLEDGE modes DoRun(DeliveryMode.PERSISTENT, Session.DUPS_OK_ACKNOWLEDGE, false); // Use NON_PERSISTENT / CLIENT_ACKNOWLEDGE modes DoRun(DeliveryMode.NON_PERSISTENT, Session.CLIENT_ACKNOWLEDGE, false); // Use NON_PERSISTENT / AUTO_ACKNOWLEDGE modes DoRun(DeliveryMode.NON_PERSISTENT, Session.AUTO_ACKNOWLEDGE, false); // Use NON_PERSISTENT / DUPS_OK_ACKNOWLEDGE modes DoRun(DeliveryMode.NON_PERSISTENT, Session.DUPS_OK_ACKNOWLEDGE, false); // Use proprietary RELIABLE_DELIVERY / NO_ACKNOWLEDGE modes DoRun(DeliveryMode.RELIABLE_DELIVERY, Session.NO_ACKNOWLEDGE, false); connection.Close(); } catch (EMSException e) { Console.Error.WriteLine("Exception in csExtensions: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(0); } }
public csMsgProducer(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); } Console.WriteLine("\n------------------------------------------------------------------------"); Console.WriteLine("csMsgProducer SAMPLE"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost")); Console.WriteLine("User......................... " + ((userName != null)?userName:"******")); Console.WriteLine("Destination.................. " + name); Console.WriteLine("Send Asynchronously.......... " + useAsync); Console.WriteLine("Message Text................. "); for (int i = 0; i < data.Count; i++) { Console.WriteLine(data[i]); } Console.WriteLine("------------------------------------------------------------------------\n"); try { TextMessage msg; int i; if (data.Count == 0) { Console.Error.WriteLine("Error: must specify at least one message text\n"); Usage(); } Console.WriteLine("Publishing to destination '" + name + "'\n"); ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); connection = factory.CreateConnection(userName, password); // create the session session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE); // create the destination if (useTopic) { destination = session.CreateTopic(name); } else { destination = session.CreateQueue(name); } // create the producer msgProducer = session.CreateProducer(null); if (useAsync) { completionListener = new EMSCompletionListener(); } // publish messages for (i = 0; i < data.Count; i++) { // create text message msg = session.CreateTextMessage(); // set message text msg.Text = (String)data[i]; // publish message if (useAsync) { msgProducer.Send(destination, msg, completionListener); } else { msgProducer.Send(destination, msg); } Console.WriteLine("Published message: " + data[i]); } // close the connection connection.Close(); } catch (EMSException e) { Console.Error.WriteLine("Exception in csMsgProducer: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(-1); } }
public csMsgConsumerPerf(String[] args) { ParseArgs(args); Console.WriteLine("\n------------------------------------------------------------------------"); Console.WriteLine("csMsgConsumer SAMPLE"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost")); Console.WriteLine("User......................... " + ((userName != null)?userName:"******")); Console.WriteLine("Destination.................. " + name); Console.WriteLine("Consumer Threads............. " + threads); Console.WriteLine("Consumer Connections......... " + connections); Console.WriteLine("Ack Mode..................... " + AcknowledgeModeName(ackMode)); if (useTxn) { Console.WriteLine("Transaction Size............. " + txnSize); } Console.WriteLine("------------------------------------------------------------------------\n"); try { Console.WriteLine("Subscribing to destination '" + name + "'\n"); ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); connsVector = new ArrayList(connections); for (int i = 0; i < connections; i++) { Connection conn = factory.CreateConnection(userName, password); conn.Start(); connsVector.Add(conn); } startTime = ArrayList.Synchronized(new ArrayList(threads)); endTime = ArrayList.Synchronized(new ArrayList(threads)); ArrayList tv = new ArrayList(threads); for (int i = 0; i < threads; i++) { Thread t = new Thread(new ThreadStart(this.Run)); tv.Add(t); t.Start(); } if (runTime > 0) { Thread.Sleep(runTime * 1000); stopNow = true; for (int i = 0; i < threads; i++) { Thread t = (Thread)tv[i]; t.Interrupt(); } } for (int i = 0; i < threads; i++) { Thread t = (Thread)tv[i]; try { t.Join(); } catch (ThreadInterruptedException e) { Console.Error.WriteLine("Exception in csMsgProducerPerf: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(0); } } for (int i = 0; i < connections; i++) { Connection conn = (Connection)connsVector[i]; // close the connection conn.Close(); } // Print performance Console.WriteLine(Performance); } catch (EMSException e) { Console.Error.WriteLine("Exception in csMsgConsumer: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(-1); } }
public csMsgProducerPerf(String[] args) { ParseArgs(args); Console.WriteLine("\n------------------------------------------------------------------------"); Console.WriteLine("csMsgProducerPerf SAMPLE"); Console.WriteLine("------------------------------------------------------------------------"); Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost")); Console.WriteLine("User......................... " + ((userName != null)?userName:"******")); Console.WriteLine("Destination.................. " + name); Console.WriteLine("Message Size................. " + (payloadFile != null ? payloadFile : msgSize.ToString())); Console.WriteLine("Count........................ " + count); Console.WriteLine("Production Threads........... " + threads); Console.WriteLine("Production Connections....... " + connections); Console.WriteLine("DeliveryMode................. " + DeliveryModeName(delMode)); Console.WriteLine("Compression.................. " + compression); Console.WriteLine("Asynchronous Sending......... " + async); if (msgRate > 0) { Console.WriteLine("Message Rate................. " + msgRate); } if (useTxn) { Console.WriteLine("Transaction Size............. " + txnSize); } Console.WriteLine("------------------------------------------------------------------------\n"); try { Console.WriteLine("Publishing to destination '" + name + "'\n"); ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl); connsVector = new ArrayList(connections); for (int i = 0; i < connections; i++) { Connection conn = factory.CreateConnection(userName, password); connsVector.Add(conn); } ArrayList tv = new ArrayList(threads); for (int i = 0; i < threads; i++) { Thread t = new Thread(new ThreadStart(this.Run)); tv.Add(t); t.Start(); } if (runTime > 0) { Thread.Sleep(runTime * 1000); stopNow = true; } for (int i = 0; i < threads; i++) { Thread t = (Thread)tv[i]; try { t.Join(); } catch (ThreadInterruptedException e) { Console.Error.WriteLine("Exception in csMsgProducerPerf: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(0); } } for (int i = 0; i < connections; i++) { Connection conn = (Connection)connsVector[i]; // close the connection conn.Close(); } // Print performance PrintPerformance(); } catch (EMSException e) { Console.Error.WriteLine("Exception in csMsgProducerPerf: " + e.Message); Console.Error.WriteLine(e.StackTrace); Environment.Exit(-1); } }