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 static void SendReplyMessage(TIBCO.EMS.Message msg, TIBCO.EMS.Queue ReplyQueue, ref Session session) { try { TIBCO.EMS.MessageProducer producer = session.CreateProducer(ReplyQueue); producer.Send(msg); } catch (EMSException e) { throw e; } }
public static void SendMessage(TIBCO.EMS.Message msg, TIBCO.EMS.Queue queue) { try { Session session = Messaging.EMS.Connection.EMSQueueConnection.connection.CreateSession(false, Session.CLIENT_ACKNOWLEDGE); TIBCO.EMS.MessageProducer producer = session.CreateProducer(queue); producer.Send(msg); } catch (EMSException e) { throw e; } }
protected override void AfterReconnect() { _msgProducer = Session.CreateProducer(Destination); }
public EmsMessageProducer(MessageProducer messageProducer) { this.nativeMessageProducer = messageProducer; }
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); 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); } }
/// <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(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); producer = session.CreateProducer(destination); producer.MsgDeliveryMode = MessageDeliveryMode.Persistent; connection.Start(); } catch (EMSException e) { Log.TraceData(Log.Source, TraceEventType.Error, 15003, "Queue initialization error. " + e); throw; } initialized = true; } }