private void CreateMocks()
        {
            mockConnectionFactory = (IConnectionFactory) mocks.CreateMock(typeof (IConnectionFactory));
            mockConnection = (IConnection) mocks.CreateMock(typeof (IConnection));
            mockSession = (ISession) mocks.CreateMock(typeof (ISession));

            TIBCO.EMS.Queue queue = new TIBCO.EMS.Queue("test"); //(Queue) mocks.CreateMock(typeof (Queue));

            Expect.Call(mockConnectionFactory.CreateConnection()).Return(mockConnection).Repeat.Once();
            if (UseTransactedTemplate)
            {
                Expect.Call(mockConnection.CreateSession(true, Session.SESSION_TRANSACTED)).Return(mockSession).Repeat.
                    Once();
            }
            else
            {
                Expect.Call(mockConnection.CreateSession(false, Session.AUTO_ACKNOWLEDGE)).Return(mockSession).
                    Repeat.
                    Once();
            }
            Expect.Call(mockSession.Transacted).Return(true);

            mockDestinationResolver =
                (IDestinationResolver) mocks.CreateMock(typeof (IDestinationResolver));
            mockDestinationResolver.ResolveDestinationName(mockSession, "testDestination", false);
            LastCall.Return(queue).Repeat.Any();
        }
        private void CreateMocks()
        {
            mockConnectionFactory = (IConnectionFactory)mocks.CreateMock(typeof(IConnectionFactory));
            mockConnection        = (IConnection)mocks.CreateMock(typeof(IConnection));
            mockSession           = (ISession)mocks.CreateMock(typeof(ISession));

            TIBCO.EMS.Queue queue = new TIBCO.EMS.Queue("test"); //(Queue) mocks.CreateMock(typeof (Queue));

            Expect.Call(mockConnectionFactory.CreateConnection()).Return(mockConnection).Repeat.Once();
            if (UseTransactedTemplate)
            {
                Expect.Call(mockConnection.CreateSession(true, Session.SESSION_TRANSACTED)).Return(mockSession).Repeat.
                Once();
            }
            else
            {
                Expect.Call(mockConnection.CreateSession(false, Session.AUTO_ACKNOWLEDGE)).Return(mockSession).
                Repeat.
                Once();
            }
            Expect.Call(mockSession.Transacted).Return(true);

            mockDestinationResolver =
                (IDestinationResolver)mocks.CreateMock(typeof(IDestinationResolver));
            mockDestinationResolver.ResolveDestinationName(mockSession, "testDestination", false);
            LastCall.Return(queue).Repeat.Any();
        }
    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 static void SendReplyMessage(TIBCO.EMS.Message ReplyMessage, TIBCO.EMS.Queue ReplyQueue)
 {
     try {
         Session session = Messaging.EMS.Connection.EMSQueueConnection.connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);
         Messaging.EMS.Producers.Messageproducer.SendReplyMessage(ReplyMessage, ReplyQueue, ref session);
     }
     catch (EMSException e) { throw e; }
 }
        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; }
        }
 private void LookupQueue(ILookupContext searcher, String name)
 {
     TIBCO.EMS.Queue queue = (TIBCO.EMS.Queue)searcher.Lookup(name);
     if (queue != null)
     {
         Console.WriteLine("");
         Console.WriteLine("########## Topic ######### ");
         Console.WriteLine(queue.ToString());
         Console.WriteLine("########################## ");
     }
 }
 public static Message SendRequestAndReceiveReply(TIBCO.EMS.Message msg, TIBCO.EMS.Queue queue)
 {
     try
     {
         QueueSession             session = Messaging.EMS.Connection.EMSQueueConnection.connection.CreateQueueSession(false, Session.AUTO_ACKNOWLEDGE);
         TIBCO.EMS.QueueRequestor qr      = new TIBCO.EMS.QueueRequestor(session, queue);
         Message ReplyMessage             = qr.Request(msg);
         qr.Close();
         return(ReplyMessage);
     }
     catch (EMSException e) { throw e; }
 }
Beispiel #8
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);
        }
    }
        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; }
        }
Beispiel #10
0
 public QueueBrowser CreateBrowser(Queue queue, string messageSelector)
 {
     return nativeSession.CreateBrowser(queue, messageSelector);
 }
Beispiel #11
0
 public QueueBrowser CreateBrowser(Queue queue)
 {
     return nativeSession.CreateBrowser(queue);
 }
Beispiel #12
0
 public QueueBrowser CreateBrowser(Queue queue, string messageSelector)
 {
     throw new NotImplementedException();
 }
Beispiel #13
0
 public QueueBrowser CreateBrowser(Queue queue)
 {
     throw new NotImplementedException();
 }
Beispiel #14
0
    public csLookup(String[] args)
    {
        parseArgs(args);
        if (providerUrl == null)
        {
            providerUrl = defaultProviderURL;
        }

        // Print parameters
        Console.WriteLine("\n------------------------------------------------------------------------");
        Console.WriteLine("csLookup SAMPLE");
        Console.WriteLine("------------------------------------------------------------------------");
        Console.WriteLine("Server....................... " + providerUrl);
        Console.WriteLine("------------------------------------------------------------------------\n");

        try
        {
            Hashtable env = new Hashtable();

            env.Add(LookupContext.PROVIDER_URL, providerUrl);
            if (userName != null)
            {
                env.Add(LookupContext.SECURITY_PRINCIPAL, userName);
                if (password != null)
                {
                    env.Add(LookupContext.SECURITY_CREDENTIALS, password);
                }
            }

            LookupContext lcxt = new LookupContext(env);

            // Lookup connection factory which must exist in the factories
            // config file.
            ConnectionFactory factory = (ConnectionFactory)lcxt.Lookup("ConnectionFactory");
            Console.WriteLine("OK - successfully did lookup ConnectionFactory");

            // Let's create a connection to the server and a session to verify
            // that the server is running so we can continue with our lookup
            // operations.
            Connection connection = null;
            Session    session    = null;

            try
            {
                connection = factory.CreateConnection(userName, password);
                session    = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);
            }
            catch (EMSException e)
            {
                Console.Error.WriteLine("**EMSException occurred while creating connection");
                Console.Error.WriteLine("  Most likely the server is not running, the exception trace follows:");
                Console.Error.WriteLine(e.StackTrace);
                Environment.Exit(0); // Can't lookup anything anyway
            }

            // Lookup topic 'topic.sample' which must exist in the topics
            // configuration file; if not successfull then most likely such
            // topic does not exist in the config files.
            Topic sampleTopic = null;
            try
            {
                sampleTopic = (Topic)lcxt.Lookup("topic.sample");
                Console.WriteLine("OK - successfully did lookup topic 'topic.sample'");
            }
            catch (NamingException ne)
            {
                Console.Error.WriteLine(ne.StackTrace);
                Console.Error.WriteLine("**NamingException occurred while looking up the topic topic.sample");
                Console.Error.WriteLine("  Most likely such topic does not exist in your configuration.");
                Console.Error.WriteLine("  Exception message follows:");
                Console.Error.WriteLine(ne.Message);
                Environment.Exit(0);
            }

            // Lookup queue 'queue.sample' which must exist in the queues
            // configuration file; if not successfull then it does not exist.
            TIBCO.EMS.Queue sampleQueue = null;
            try
            {
                sampleQueue = (TIBCO.EMS.Queue)lcxt.Lookup("queue.sample");
                Console.WriteLine("OK - successfully did lookup queue 'queue.sample'");
            }
            catch (NamingException ne)
            {
                Console.Error.WriteLine("**NamingException occurred while looking up the queue queue.sample");
                Console.Error.WriteLine("  Most likely such topic does not exist in your configuration.");
                Console.Error.WriteLine("  Exception message follows:");
                Console.Error.WriteLine(ne.Message);
                Environment.Exit(0);
            }

            // Try to lookup a topic when a topic *and* a queue with the
            // same name exist in the configuration. The sample configuration
            // has both topic and queue with the name 'sample' used here. If
            // everything is OK, we will get an exception, then try to lookup
            // those objects using fully-qualified names.
            try
            {
                Object object_Renamed = lcxt.Lookup("sample");

                // If the sample config was not altered, we should not get to this
                // line because lookup() should throw an exception.
                Console.WriteLine("Object named 'sample' has been looked up as: " + object_Renamed);
            }
            catch (NamingException ne)
            {
                Console.Error.WriteLine("OK - NamingException occurred while looking up the object named 'sample'");
                Console.Error.WriteLine("     This is the CORRECT BEHAVIOUR if the exception message below");
                Console.Error.WriteLine("     specifies name conflict situation. Exception message follows:");
                Console.Error.WriteLine("     " + ne.Message);

                // Let's look them up using name qualifiers.
                try
                {
                    Topic t = (Topic)lcxt.Lookup("$topics.sample");
                    Console.WriteLine("OK - successfully did lookup topic '$topics.sample'");
                    TIBCO.EMS.Queue q = (TIBCO.EMS.Queue)lcxt.Lookup("$queues.sample");
                    Console.WriteLine("OK - successfully did lookup queue '$queues.sample'");
                }
                catch (NamingException nex)
                {
                    // These may not be configured: Print a warning and continue.
                    Console.Error.WriteLine("**NamingException occurred while looking up the topic or queue 'sample'");
                    Console.Error.WriteLine("  Exception message follows:");
                    Console.Error.WriteLine("  " + nex.Message);
                }
            }

            // Now let's try to lookup a topic which definitely does not
            // exist. A lookup() operation will throw an exception and then we
            // will try to create such topic explicitly with the createTopic()
            // method.
            String dynamicName  = "topic.does.not.exist." + (DateTime.Now.Ticks - 621355968000000000) / 10000;
            Topic  dynamicTopic = null;
            try
            {
                dynamicTopic = (Topic)lcxt.Lookup(dynamicName);

                // If the sample config was not altered, we should not get to
                // this line because lookup() should throw an exception.
                Console.Error.WriteLine("**Error: dynamic topic " + dynamicName + " found by lookup");
            }
            catch (NamingException)
            {
                // This is OK.
                Console.Error.WriteLine("OK - could not lookup dynamic topic " + dynamicName);
            }

            // Try to create it.
            try
            {
                dynamicTopic = session.CreateTopic(dynamicName);
                Console.WriteLine("OK - successfully created dynamic topic " + dynamicName);
            }
            catch (EMSException e)
            {
                // A few reasons are possible here. Maybe there is no > entry
                // in the topics configuration or the server security is
                // turned on. If the original sample configuration is used, this
                // should work.
                Console.Error.WriteLine("**EMSException occurred while creating topic " + dynamicName);
                Console.Error.WriteLine("  Please verify your topics configuration and security settings.");
                Console.Error.WriteLine(e.StackTrace);
                Environment.Exit(0);
            }

            connection.Close();

            Console.WriteLine("OK - Done.");
        }
        catch (EMSException e)
        {
            Console.Error.WriteLine(e.StackTrace);
            Environment.Exit(0);
        }
    }
Beispiel #15
0
    public csLookupSSL(String[] args)
    {
        parseArgs(args);
        if (providerUrl == null)
        {
            providerUrl = defaultProviderURL;
        }

        // Print parameters
        Console.WriteLine("\n------------------------------------------------------------------------");
        Console.WriteLine("csLookupSSL SAMPLE");
        Console.WriteLine("------------------------------------------------------------------------");
        Console.WriteLine("Server....................... " + providerUrl);
        Console.WriteLine("------------------------------------------------------------------------\n");

        try
        {
            Hashtable env = new Hashtable();

            env.Add(LookupContext.PROVIDER_URL, providerUrl);
            if (userName != null)
            {
                env.Add(LookupContext.SECURITY_PRINCIPAL, userName);
                if (password != null)
                {
                    env.Add(LookupContext.SECURITY_CREDENTIALS, password);
                }
            }

            // Creating the SSL related file store info object.
            EMSSSLFileStoreInfo info = new EMSSSLFileStoreInfo();
            if (ssl_identity != null)
            {
                info.SetSSLClientIdentity(ssl_identity);
            }

            if (ssl_password != null)
            {
                string _sslpassword = ssl_password;
                info.SetSSLPassword(_sslpassword.ToCharArray());
            }

            if (ssl_target_hostname == null)
            {
                Console.WriteLine("ssl_target_hostname is required parameter");
                usage();
            }

            // Setting up the SSL properties for the lookup context.
            env.Add(LookupContext.SSL_STORE_INFO, info);
            env.Add(LookupContext.SSL_STORE_TYPE, EMSSSLStoreType.EMSSSL_STORE_TYPE_FILE);
            env.Add(LookupContext.SECURITY_PROTOCOL, "ssl");
            env.Add(LookupContext.SSL_TARGET_HOST_NAME, ssl_target_hostname);

            LookupContext lcxt = new LookupContext(env);

            // Lookup connection factory which must exist in the factories config file.

            ConnectionFactory factory    = null;
            ConnectionFactory sslFactory = null;

            try
            {
                factory = (ConnectionFactory)lcxt.Lookup("ConnectionFactory");
                Console.WriteLine("OK - successfully did lookup ConnectionFactory");

                // Lookup SSL connection factory which must exist in the
                // factories config file.
                sslFactory = (ConnectionFactory)lcxt.Lookup("SSLConnectionFactory");
                Console.WriteLine("OK - successfully did lookup SSLConnectionFactory");

                // Setting additional parameters for this SSL factory.
                sslFactory.SetTargetHostName(ssl_target_hostname);

                // Also, if users want to set any other SSL parameters,
                // i.e EMSSSLFileStoreInfo parameters, they can call GetCertificateStore
                // on the connection factory object.
                EMSSSLFileStoreInfo fileStoreInfo = (EMSSSLFileStoreInfo)sslFactory.GetCertificateStore();
                fileStoreInfo.SetSSLClientIdentity(ssl_identity);
                string _sslpassword = ssl_password;
                fileStoreInfo.SetSSLPassword(_sslpassword.ToCharArray());
            }
            catch (EMSException e)
            {
                Console.Error.WriteLine("**EMSException occurred while doing a lookup");
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.StackTrace);
                Environment.Exit(0); // Can't lookup anything anyway
            }

            // Let's create a connection to the server and a session to verify
            // that the server is running.
            Connection sslConnection = null;
            Session    sslSession    = null;

            try
            {
                sslConnection = sslFactory.CreateConnection(userName, password);
                sslSession    = sslConnection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);
                sslConnection.Close();
            }
            catch (EMSException e)
            {
                Console.Error.WriteLine("**EMSException occurred while creating SSL connection");
                Console.Error.WriteLine("  Most likely the server is not running, the exception trace follows:");
                Console.Error.WriteLine(e.StackTrace);
                Environment.Exit(0); // Can't lookup anything anyway
            }

            // Let's create a connection to the server and a session to verify
            // that the server is running so we can continue with our lookup operations.
            Connection connection = null;
            Session    session    = null;

            try
            {
                connection = factory.CreateConnection(userName, password);
                session    = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);
            }
            catch (EMSException e)
            {
                Console.Error.WriteLine("**EMSException occurred while creating connection");
                Console.Error.WriteLine("  Most likely the server is not running, the exception trace follows:");
                Console.Error.WriteLine(e.StackTrace);
                Environment.Exit(0); // Can't lookup anything anyway
            }

            // Lookup topic 'topic.sample' which must exist in the topics
            // configuration file; if not successfull then most likely such
            // topic does not exist in the config file.
            Topic sampleTopic = null;
            try
            {
                sampleTopic = (Topic)lcxt.Lookup("topic.sample");
                Console.WriteLine("OK - successfully did lookup topic 'topic.sample'");
            }
            catch (NamingException ne)
            {
                Console.Error.WriteLine(ne.StackTrace);
                Console.Error.WriteLine("**NamingException occurred while lookup the topic topic.sample");
                Console.Error.WriteLine("  Most likely such topic does not exist in your configuration.");
                Console.Error.WriteLine("  Exception message follows:");
                Console.Error.WriteLine(ne.Message);
                Environment.Exit(0);
            }

            // Lookup queue 'queue.sample' which must exist in the queues
            // configuration file; if not successfull then it does not exist.
            TIBCO.EMS.Queue sampleQueue = null;
            try
            {
                sampleQueue = (TIBCO.EMS.Queue)lcxt.Lookup("queue.sample");
                Console.WriteLine("OK - successfully did lookup queue 'queue.sample'");
            }
            catch (NamingException ne)
            {
                Console.Error.WriteLine("**NamingException occurred while lookup the queue queue.sample");
                Console.Error.WriteLine("  Most likely such topic does not exist in your configuration.");
                Console.Error.WriteLine("  Exception message follows:");
                Console.Error.WriteLine(ne.Message);
                Environment.Exit(0);
            }

            // Try to lookup a topic when a topic *and* a queue with the
            // same name exist in the configuration. The sample configuration
            // has both topic and queue with the name 'sample' used here. If
            // everything is OK, we will get an exception, then try to lookup
            // those objects using fully-qualified names.
            try
            {
                Object object_Renamed = lcxt.Lookup("sample");

                // If the sample config was not altered, we should not get to this
                // line because lookup() should throw an exception.
                Console.WriteLine("Object named 'sample' has been looked up as: " + object_Renamed);
            }
            catch (NamingException ne)
            {
                Console.Error.WriteLine("OK - NamingException occurred while lookup the object named 'sample'");
                Console.Error.WriteLine("     This is the CORRECT BEHAVIOUR if the exception message below");
                Console.Error.WriteLine("     specifies name conflict situation. Exception message follows:");
                Console.Error.WriteLine("     " + ne.Message);

                // Let's look them up using name qualifiers.
                try
                {
                    Topic t = (Topic)lcxt.Lookup("$topics.sample");
                    Console.WriteLine("OK - successfully did lookup topic '$topics.sample'");
                    TIBCO.EMS.Queue q = (TIBCO.EMS.Queue)lcxt.Lookup("$queues.sample");
                    Console.WriteLine("OK - successfully did lookup queue '$queues.sample'");
                }
                catch (NamingException nex)
                {
                    // These may not be configured: Print a warning and continue.
                    Console.Error.WriteLine("**NamingException occurred while lookup the topic or queue 'sample'");
                    Console.Error.WriteLine("  Exception message follows:");
                    Console.Error.WriteLine("  " + nex.Message);
                }
            }

            // Now let's try to lookup a topic which definitely does not
            // exist. A lookup() operation will throw an exception and then we
            // will try to create such a topic explicitly with the createTopic()
            // method.
            String dynamicName  = "topic.does.not.exist." + (DateTime.Now.Ticks - 621355968000000000) / 10000;
            Topic  dynamicTopic = null;
            try
            {
                dynamicTopic = (Topic)lcxt.Lookup(dynamicName);

                // If the sample config was not altered, we should not get to
                // this line because lookup() should throw an exception.
                Console.Error.WriteLine("**Error: dynamic topic " + dynamicName + " found by lookup");
            }
            catch (NamingException)
            {
                // This is OK.
                Console.Error.WriteLine("OK - could not lookup dynamic topic " + dynamicName);
            }

            // Try to create it.
            try
            {
                dynamicTopic = session.CreateTopic(dynamicName);
                Console.WriteLine("OK - successfully created dynamic topic " + dynamicName);
            }
            catch (EMSException e)
            {
                // A few reasons are possible here. Maybe there is no > entry
                // in the topics configuration or the server security is
                // turned on. If the original sample configuration is used, this
                // should work.
                Console.Error.WriteLine("**EMSException occurred while creating topic " + dynamicName);
                Console.Error.WriteLine("  Please verify your topics configuration and security settings.");
                Console.Error.WriteLine(e.StackTrace);
                Environment.Exit(0);
            }

            connection.Close();

            Console.WriteLine("OK - Done.");
        }
        catch (EMSException e)
        {
            Console.Error.WriteLine(e.StackTrace);
            Environment.Exit(0);
        }
    }
Beispiel #16
0
 /// <summary>
 /// Browses messages in a EMS queue. The callback gives access to the EMS Session
 /// and QueueBrowser in order to browse the queue and react to the contents.
 /// </summary>
 /// <param name="queue">The queue to browse.</param>
 /// <param name="action">The action callback delegate that exposes the session/browser pair.</param>
 /// <returns>the result object from working with the session</returns>
 public object BrowseWithDelegate(Queue queue, BrowserDelegate action)
 {
     return BrowseSelectedWithDelegate(queue, null, action);
 }
Beispiel #17
0
 public QueueBrowser CreateBrowser(Queue queue)
 {
     this.transactionOpen = true;
     return(target.CreateBrowser(queue));
 }
Beispiel #18
0
 public QueueBrowser CreateBrowser(Queue queue, string messageSelector)
 {
     this.transactionOpen = true;
     return(target.CreateBrowser(queue, messageSelector));
 }
 public QueueBrowser CreateBrowser(Queue queue)
 {
     this.transactionOpen = true;
     return target.CreateBrowser(queue);
 }
Beispiel #20
0
 /// <summary>
 /// Creates the queue browser.
 /// </summary>
 /// <param name="session">The session.</param>
 /// <param name="queue">The queue.</param>
 /// <param name="selector">The selector.</param>
 /// <returns>A new queue browser</returns>
 protected virtual QueueBrowser CreateBrowser(ISession session, Queue queue, string selector)
 {
     return session.CreateBrowser(queue, selector);
 }
Beispiel #21
0
 /// <summary>
 /// Browses messages in a EMS queue. The callback gives access to the EMS Session
 /// and QueueBrowser in order to browse the queue and react to the contents.
 /// </summary>
 /// <param name="queue">The queue to browse.</param>
 /// <param name="messageSelector">The EMS message selector expression (or <code>null</code> if none).</param>
 /// <param name="action">The action callback delegate that exposes the session/browser pair.</param>
 /// <returns></returns>
 /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
 public object BrowseSelectedWithDelegate(Queue queue, string messageSelector, BrowserDelegate action)
 {
     AssertUtils.ArgumentNotNull(action, "action");
     return Execute(session =>
                        {
                            QueueBrowser browser = CreateBrowser(session, queue, messageSelector);
                            try
                            {
                                return action(session, browser);
                            }
                            finally
                            {
                                EmsUtils.CloseQueueBrowser(browser);
                            }
                        }, true); 
 }
 public QueueBrowser CreateBrowser(Queue queue, string messageSelector)
 {
     this.transactionOpen = true;
     return target.CreateBrowser(queue, messageSelector);
 }
Beispiel #23
0
 /// <summary>
 /// Browses messages in a EMS queue. The callback gives access to the EMS Session
 /// and QueueBrowser in order to browse the queue and react to the contents.
 /// </summary>
 /// <param name="queue">The queue to browse.</param>
 /// <param name="action">The action callback object that exposes the session/browser pair.</param>
 /// <returns>the result object from working with the session</returns>
 /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>        
 public object Browse(Queue queue, IBrowserCallback action)
 {
     AssertUtils.ArgumentNotNull(action, "action");
     return BrowseSelectedWithDelegate(queue, null, action.DoInEms);
 }
Beispiel #24
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);
        }
    }
Beispiel #25
0
 /// <summary>
 /// Browses messages in a EMS queue. The callback gives access to the EMS Session
 /// and QueueBrowser in order to browse the queue and react to the contents.
 /// </summary>
 /// <param name="queue">The queue to browse.</param>
 /// <param name="messageSelector">The EMS message selector expression (or <code>null</code> if none).</param>
 /// <param name="action">The action callback object that exposes the session/browser pair.</param>
 /// <returns></returns>
 /// <exception cref="EMSException">If there is any problem accessing the EMS API</exception>
 public object BrowseSelected(Queue queue, string messageSelector, IBrowserCallback action)
 {
     AssertUtils.ArgumentNotNull(action, "action");
     return BrowseSelectedWithDelegate(queue, messageSelector, action.DoInEms);        
 }