Exemplo n.º 1
0
        public SyncMessageConsumerUsingReceieve(string EMSQueueName, int NoOfSessions, int Timeout)
        {
            for (int i = 0; i < NoOfSessions; i++)
            {
                QueueSession  session  = Messaging.EMS.Connection.EMSQueueConnection.connection.CreateQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE);
                Queue         queue    = session.CreateQueue(EMSQueueName);
                QueueReceiver receiver = session.CreateReceiver(queue);
                Message       ReceivedMessage;


                Thread t1 = new Thread(() =>
                {
                    Thread.CurrentThread.Name = "Explicit Thread for Session-" + session.SessID;
                    if ((ReceivedMessage = receiver.Receive(Timeout)) != null)
                    {
                        this.ReceiveAndProcessMessage(ReceivedMessage);

                        /* A Receive call that returns as and when message is received or when it timesout . Achieves concurrent
                         * consumption thats one-time i.e as soon as processing is completed ,so is the thread.
                         * Sync. consumer will be required when a flow triggered by some non-ems mechanism/protocol needs to
                         * fetch messages off EMS . Most likely, NoOfSessions=1 and Timeout=<int>  in this sceanrio.
                         * Main thread does not wait for the threads to finish , however multiple receivers/consumers so created
                         * will be destroyed all at once and not one-by-one.
                         * You dont want it to put in loop , unlike in the other constructor , because there is not much use
                         * repeating something that did not fetch anything in first place and had to time out.Rather
                         * this mechanism is better suited  where possibilty of message arrival is rather low or producer is sluggish.
                         */
                    }
                }

                                       );

                t1.Start();
            }
        }
Exemplo n.º 2
0
        //protected String EMSQueueName;
        //protected int  NoOfSessions;
        public SyncMessageConsumerUsingReceieve(string EMSQueueName, int NoOfSessions, Boolean KeepAlive)
        {
            for (int i = 0; i < NoOfSessions; i++)
            {
                QueueSession  session  = Messaging.EMS.Connection.EMSQueueConnection.connection.CreateQueueSession(false, QueueSession.CLIENT_ACKNOWLEDGE);
                Queue         queue    = session.CreateQueue(EMSQueueName);
                QueueReceiver receiver = session.CreateReceiver(queue);
                Message       ReceivedMessage;


                Thread t1 = new Thread(() =>
                {
                    Thread.CurrentThread.Name = "Explicit Thread for Session-" + session.SessID;
                    while ((ReceivedMessage = receiver.Receive()) != null)
                    {
                        this.ReceiveAndProcessMessage(ReceivedMessage);
                        if (!KeepAlive)
                        {
                            break; /* With NoOfSessions=1 and KeepAlive=false , achieves effect of a single Receive call that
                                    * returns as and when message is received. NoOfSessions > 1 and KeepAlive=false  achieves concurrent
                                    * consumption thats one-time i.e as soon as processing is completed ,so is the thread.
                                    * Sync. consumer will be required when a flow triggered by some non-ems mechanism/protocol needs to
                                    * fetch messages off EMS . Most likely, NoOfSessions=1 and KeepAlive=false  in this sceanrio.
                                    * Main thread does not wait for the threads to finish , however multiple receivers/consumers so created
                                    * will be destroyed all at once and not one-by-one.
                                    */
                        }
                    }
                }

                                       );

                t1.Start();
            }
        }
Exemplo n.º 3
0
    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);
        }
    }
Exemplo n.º 4
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);
        }
    }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("\n  The Message Producing Pattern has to be either FF or RR\n" + "  Usage:" +

                                  Process.GetCurrentProcess().ProcessName + "  FF(or RR)  CorrelationID");

                Environment.Exit(-1);
            }

            try
            {
                QueueSession session = Messaging.EMS.Connection.EMSQueueConnection.connection.CreateQueueSession(false, Session.AUTO_ACKNOWLEDGE);

                Queue queue = session.CreateQueue(System.Configuration.ConfigurationManager.AppSettings["QueueName"]);

                Process CurrentProcess = Process.GetCurrentProcess();

                String MainThreadName = Environment.MachineName + "_" + CurrentProcess.ProcessName + "_" + CurrentProcess.Id;
                Thread.CurrentThread.Name = MainThreadName;

                msg = (TextMessage)session.CreateTextMessage("hellothere-");

                string Text =
                    "\n\n MachineName : " + Environment.MachineName +
                    "\n SendingProcessName : " + Process.GetCurrentProcess().ProcessName +
                    "\n SendingProcessId : " + Process.GetCurrentProcess().Id +
                    "\n Method : " + System.Reflection.MethodBase.GetCurrentMethod().Name +
                    "\n ThreadName:\"" + Thread.CurrentThread.Name + "\"" +
                    "\n ClientId: " + Messaging.EMS.Connection.EMSQueueConnection.connection.ClientID;
                string seperator = "\n\n*****************************************************************************************\n";

                msg.Text += Text;
                try { msg.CorrelationID = (args[1]); } /*Absorb this AOOB exception :) */ catch (Exception e) { };


                switch (args[0])
                {
                case "FF":
                    Console.WriteLine(seperator + "About to Fire (and Forget ) :\n\n" + msg.ToString());
                    Messaging.EMS.Producers.Messageproducer.SendMessage(msg, queue);
                    break;

                case "RR":
                    Console.WriteLine(seperator + "About to send request:\n\n" + msg.ToString());
                    Message reply = Messaging.EMS.Producers.Messageproducer.SendRequestAndReceiveReply(msg, queue);
                    if (reply is TextMessage)
                    {
                        Console.WriteLine(seperator + "Received Response:\n\n" + reply.ToString());
                    }
                    break;

                default:
                    Console.WriteLine("The Message Producing Pattern has to be either FF or RR  ");
                    Environment.Exit(-1);
                    break;
                }



                // Messaging.EMS.Producers.Messageproducer.SendMessage(msg, queue);
            }
            catch (Exception e) { Console.WriteLine("\n\n*********Exception thrown:\n" + "\n\n***********" + e.StackTrace + e.ToString()); }
        }