Exemple #1
0
    private void stopTiming(EMSCompletionListener cl, int count)
    {
        long et = DateTime.Now.Ticks;
        long ct = 0;

        if (cl != null)
        {
            cl.FinishCount = count;
            cl.WaitUntilFinished();
            ct = cl.CompletionTime;
        }

        lock (this)
        {
            if (et > endTime)
            {
                endTime = et;
            }

            if (ct > completionTime)
            {
                completionTime = ct;
            }
        }
    }
    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 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);
        }
    }
Exemple #4
0
    public void Run()
    {
        int                   msgCount       = 0;
        MsgRateChecker        msgRateChecker = null;
        EMSCompletionListener cl             = null;
        int                   numMsgsToPublish;

        try
        {
            Thread.Sleep(500);
        }
        catch (ThreadInterruptedException) {}

        try
        {
            // create the session
            Connection connection = this.MyConnection;
            Session    session    = connection.CreateSession(useTxn, Session.AUTO_ACKNOWLEDGE);

            // create the destination
            Destination destination = CreateDestination(session);

            // create the producer
            MessageProducer msgProducer = session.CreateProducer(null);

            if (async)
            {
                cl = new EMSCompletionListener();
            }

            // set parameters on producer
            msgProducer.DeliveryMode = delMode;
            // Specific for performance
            msgProducer.DisableMessageID        = true;
            msgProducer.DisableMessageTimestamp = true;

            // create the message
            Message msg = CreateMessage(session);

            if (uniqueDests || useTopic)
            {
                numMsgsToPublish = count;
            }
            else
            {
                numMsgsToPublish = count / threads;
            }

            if (compression)
            {
                msg.SetBooleanProperty("JMS_TIBCO_COMPRESS", true);
            }

            // initialize message rate checking
            if (msgRate > 0)
            {
                msgRateChecker = new MsgRateChecker(msgRate);
            }

            startTiming();

            while ((count == 0 || msgCount < numMsgsToPublish) && !stopNow)
            {
                // publish message
                if (async)
                {
                    msgProducer.Send(destination, msg, cl);
                }
                else
                {
                    msgProducer.Send(destination, msg);
                }

                msgCount++;

                // commit messages
                if (useTxn && (msgCount % txnSize) == (txnSize - 1))
                {
                    session.Commit();
                }

                if (msgRate > 0)
                {
                    msgRateChecker.checkMsgRate(msgCount);
                }
            }

            // commit remaining messages
            if (useTxn)
            {
                session.Commit();
            }

            stopTiming(cl, numMsgsToPublish);

            CountSends(msgCount);
        }
        catch (EMSException e)
        {
            Console.Error.WriteLine("Exception in csMsgProducerPerf: " +
                                    e.Message);
            Console.Error.WriteLine(e.StackTrace);

            if (e.LinkedException != null)
            {
                Console.Error.WriteLine("Linked Exception: " +
                                        e.LinkedException.Message);
                Console.Error.WriteLine(e.LinkedException.StackTrace);
            }

            Environment.Exit(-1);
        }
    }