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);
            }
        }
        private Session GetSession()
        {
            _connection = _connection ?? CreateConnection();

            _session = _session ?? _connection.CreateSession(false, Session.CLIENT_ACKNOWLEDGE);
            return _session;
        }
        public void Reconnect()
        {
            if (Session != null && !Session.IsClosed)
                Session.Close();

            Provider.Connect();
            Session = Provider.Connection.CreateSession(false, SessionMode.AutoAcknowledge);
            Destination = Session.CreateQueue(QueueName);
            AfterReconnect();
        }
        public TibcoConnection(string url, string username, string password, IEnumerable<TibcoDestination> destinations)
        {
            _url = url;
            _username = username;
            _password = password;
            _destinations = destinations.ToList();

            _session = GetSession(); //TODO: this needs a bit more thought; do we need to handle dropped sessions to tibco or does the tibco dll take care of that for us

            _destinations.ForEach(x => x.SetSession(_session)); //go ahead and connect now; if something is wrong with the connection info, fail fast; doesn't take into account temporary failure
        }
        public AsyncMessageConsumerUsingMessageListener(String QueueName, int NoOfSessions)
        {
            EMSQueueConnection.connection.Stop(); /* Iffy if multiple clients are using the conn.  */
            this.QueueName    = QueueName;
            this.NoOfSessions = NoOfSessions;

            TIBCO.EMS.Session         session     = null;
            TIBCO.EMS.MessageConsumer msgConsumer = null;
            TIBCO.EMS.Destination     destination = null;

            try
            {
                for (int i = 0; i < NoOfSessions; i++)
                {
                    /*
                     * Create a new session which in turn creates a thread interanlly .
                     * Ack mode is hard coded for now , see no possibulty for  it being other than CLient_ack*/
                    session = EMSQueueConnection.connection.CreateSession(false, Session.CLIENT_ACKNOWLEDGE);

                    // create the consumer
                    if (destination == null)
                    {
                        destination = session.CreateQueue(QueueName);
                    }
                    msgConsumer = session.CreateConsumer(destination);

                    // set the message listener
                    msgConsumer.MessageListener = this;

                    /*
                     * Console.WriteLine("\n Subscribing to destination: " + QueueName);Console.WriteLine("************************************************\n ThreadName:"
                     + System.Threading.Thread.CurrentThread.Name + "\n  Session:" + session.ToString()
                     +
                     + "\n  SessionID:" + session.SessID + "\n  Connection:" + session.Connection.ToString() +
                     + "\n  MessageConsumer:" + msgConsumer.ToString()  );*/
                }

                EMSQueueConnection.connection.Start();
                // Start pub-sub messages
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("Exception in AsyncMsgConsumer: " + e.Message);
                Console.Error.WriteLine(e.StackTrace);
            }
        }
Exemple #6
0
 public EmsSession(Session session)
 {
     this.nativeSession = session;
 }
 private static Destination CreateDestination(Session sess, string name, QueueType type)
 {
     Destination dest;
     switch (type)
     {
         case QueueType.Queue:
             dest = sess.CreateQueue(name);
             break;
         case QueueType.Topic:
             dest = sess.CreateTopic(name);
             break;
         default:
             throw new ApplicationException("Internal error");
     }
     return dest;
 }
        /// <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 void SetSession(Session session)
 {
     _session = session;
 }