Пример #1
0
    private void Run()
    {
        Console.WriteLine("Publishing to queue '" + queueName + "'\n");
        int tasks = 1000;

        // Generate random numbers, more interesting than just i being incremented
        Random rnd = new Random();

        try
        {
            for (int i = 0; i < tasks; i++)
            {
                TextMessage msg;

                ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory("localhost");
                connection = factory.CreateConnection("", "");

                // create the session
                session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);
                queue   = session.CreateQueue(queueName);

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

                msg = session.CreateTextMessage();
                var number = rnd.Next(1000, 1000000);

                // update console
                Console.WriteLine("Number : " + number);

                // load the txt - which is a number we want to now the primes
                // note: receiver uses Convert.ToInt32 so we need to only pass in valid number.
                msg.Text = number.ToString();

                //Another options is to use a property
                msg.SetIntProperty("number", number);

                //compress
                //msg.SetBooleanProperty("JMS_TIBCO_COMPRESS", true);

                //publish the message
                msgProducer.Send(queue, msg);
                Thread.Sleep(100);
            }
            Console.WriteLine("Tasks Sent : " + tasks.ToString());
        }
        catch (EMSException e)
        {
            Console.Error.WriteLine("Exception in Tasks : " + e.Message);
            Console.Error.WriteLine(e.StackTrace);
            Environment.Exit(-1);
        }
    }
Пример #2
0
    private void Run()
    {
        try
        {
            TextMessage msg;
            Console.WriteLine("Publishing to destination queue '" + queueName + "'\n");

            ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory("localhost");
            connection = factory.CreateConnection("", "");

            // create the session
            session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);
            queue   = session.CreateQueue(queueName);

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

            string xml = @"<Event Id='15040' Code='C1219_DEMAND_RESET' Severity='EVENT_SEVERITY_INFORMATION' Name='C1219 Demand Reset' Class='DemandResetOccurred'>
                                <Description> C1219 Demand Reset occurred </ Description > < Message > Demand Reset occurred for meter { 0}.</ Message>
                                <Parameter Index = '0' Name = 'sourceEmitter' Type = 'Device'/> 
                                <MetaInfo>
                                    <MeterSource> Std table 76.table proc number 20 </MeterSource>
                                </MetaInfo>
                          </Event> ";

            msg = session.CreateTextMessage();

            //Add special properties
            msg.SetStringProperty("NUMBER_OF_EVENTS", 1.ToString());

            // load the txt or xml in our use case
            msg.Text = xml;

            //compress
            msg.SetBooleanProperty("JMS_TIBCO_COMPRESS", true);

            //publish the message
            msgProducer.Send(queue, msg);
            Console.WriteLine("Published message: " + msg.ToString());
        }
        catch (EMSException e)
        {
            Console.Error.WriteLine("Exception in 3_SendTextMessage: " + e.Message);
            Console.Error.WriteLine(e.StackTrace);
            Environment.Exit(-1);
        }
    }
Пример #3
0
    private void sendMsgs(MessageProducer prod)
    {
        // publish messages, messages sent are now part of this
        // msdtc txn.
        for (int i = 0; i < count; i++)
        {
            // create text message
            TextMessage msg = session.CreateTextMessage();

            // set message text
            msg.Text = "Hello World " + i;

            // publish message
            prod.Send(msg);

            Console.WriteLine("Published message: " + i);
        }
    }
Пример #4
0
        private void BtnMsgSend_Click(object sender, EventArgs e)
        {
            // publish messages
            TextMessage msgProd;

            if (SendMsgTextBox.Text.Trim().Length != 0)
            {
                // create text message
                msgProd = sessionProd.CreateTextMessage();

                // set message text
                msgProd.Text = SendMsgTextBox.Text;
                //connectionProd.
                msgProducer.Send(destinationProd, msgProd, completionListener);

                LogTextBox.Text = LogTextBox.Text + "\nPublished message: " + SendMsgTextBox.Text;
                logger.Info("Published message: " + SendMsgTextBox.Text);
            }
        }
Пример #5
0
    private void Run()
    {
        try
        {
            BytesMessage msg;
            Console.WriteLine("Publishing to queue '" + queueName + "'\n");

            ConnectionFactory factory = new ConnectionFactory("localhost");
            connection = factory.CreateConnection("", "");

            // create the session
            session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);
            queue   = session.CreateQueue(queueName);

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

            byte[] file = File.ReadAllBytes("Nlog.xml");
            msg = session.CreateBytesMessage();
            msg.WriteBytes(file);
            msg.MsgType = "Byte";

            //Add additional properties - which function as key value pairs
            msg.SetStringProperty("FILE_SIZE", file.Length.ToString());
            msg.SetStringProperty("FILE_NAME", Guid.NewGuid().ToString());

            //compress the data
            msg.SetBooleanProperty("JMS_TIBCO_COMPRESS", true);

            //publish the message
            msgProducer.Send(queue, msg);
            Console.WriteLine("Published message: " + msg.ToString());
        }
        catch (EMSException e)
        {
            Console.Error.WriteLine("Exception in 2_SendByteMessage: " + e.Message);
            Console.Error.WriteLine(e.StackTrace);
            Environment.Exit(-1);
        }
    }
Пример #6
0
    private void Run()
    {
        try
        {
            TextMessage msg;
            Console.WriteLine("Publishing to queue '" + queueName + "'\n");

            ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory("localhost");
            connection = factory.CreateConnection("", "");

            // create the session
            session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);
            queue   = session.CreateQueue(queueName);

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

            msg = session.CreateTextMessage();

            // load the txt
            msg.Text = "Hello World";

            //compress
            msg.SetBooleanProperty("JMS_TIBCO_COMPRESS", true);

            //publish the message
            msgProducer.Send(queue, msg);
            Console.WriteLine("Published message: " + msg.ToString());
        }
        catch (EMSException e)
        {
            Console.Error.WriteLine("Exception in SendHelloWorld : " + e.Message);
            Console.Error.WriteLine(e.StackTrace);
            Environment.Exit(-1);
        }
    }
Пример #7
0
    public emsSSLSampleClient(string[] args)
    {
        if (topicName == null)
        {
            System.Console.WriteLine("Error: must specify topic name");
        }

        System.Console.WriteLine("Global SSL parameters sample with Microsoft Cerrtificate Store.");
        try
        {
            // System Store Info object to be used while setting the store type for a connection factory via the
            // ConnectionFactory.SetCertificateStoreType. The store info consists of the store location, store name,
            // the certificate name (to look for in the specified store name at the specified store location).
            // The default store location is StoreLocation.CurrentUser and the default store name is 'my' store as defined by the .NET framework.
            // The search criteria to find the certificate in the store name at the store location is X509FindType.FindBySubjectDistinguishedName.
            EMSSSLSystemStoreInfo storeInfo = new EMSSSLSystemStoreInfo();

            // set trace for client-side operations, loading of certificates
            // and other
            if (ssl_trace)
            {
                EMSSSL.SetClientTracer(new System.IO.StreamWriter(System.Console.OpenStandardError()));
            }

            // Set the target host name.
            // This is a required parameter for all.NET SSL connections.Because System.Net.Security.SslStream
            // requires a target host, this value is required.
            //
            // The name of the server as defined in the server's certificate. Usually the server's HostName
            // is specified as the CN in the server's certificate. This value must match the name on the
            // server's certificate server name.
            if (ssl_target_hostname != null)
            {
                EMSSSL.SetTargetHostName(ssl_target_hostname);
            }

            // Set location of the certificate store
            // The certificate store location indicates where to lookup the certificate by name. If no store name is specified,
            // then the default store name is "My" store name within this store location.
            // storeLocation	Location in which to lookup certificate by name. For example, "CurrentUser" or "LocalMachine."
            if (ssl_cert_store_location != null)
            {
                if (ssl_cert_store_location.Equals("currentuser"))
                {
                    storeInfo.SetCertificateStoreLocation(StoreLocation.CurrentUser);
                }
                else if (ssl_cert_store_location.Equals("localmachine"))
                {
                    storeInfo.SetCertificateStoreLocation(StoreLocation.LocalMachine);
                }
            }

            // Set the certificate store name
            // This is the name of the store in which certificates are stored. During the SSL handshake,
            // this is where the client library looks for the certificates.
            if (ssl_cert_store_name != null)
            {
                storeInfo.SetCertificateStoreName(ssl_cert_store_name);
            }

            // Set the name of the certificate as a full subject DN
            // This method sets the name of the certificate. The certificate name is the subject distinguished name of the certificate.
            // During the SSL handshake, the server searches for the named certificate in the store specified by SetCertificateStoreName
            // at the location specified by SetCertificateStoreLocation. The search criteria to find the certificate in the store name
            // at the store location is X509FindType.FindBySubjectDistinguishedName.
            // A subject DN sample
            //      [email protected], CN=client, OU=client Unit, O=Test Company, L=us-english, S=California, C=US
            if (ssl_cert_name != null)
            {
                storeInfo.SetCertificateNameAsFullSubjectDN(ssl_cert_name);
            }

            // Set the store type for ALL the connection factories
            // If the store type is EMSSSL_STORE_TYPE_SYSTEM, then storeInfo must be an EMSSSLSystemStoreInfo object. If the store type is
            // EMSSSL_STORE_TYPE_FILE, then storeInfo must be an EMSSSLFileStoreInfo object.
            // The type of certificate store. Can be either EMSSSL_STORE_TYPE_SYSTEM or EMSSSL_STORE_TYPE_FILE. See EMSSSLStoreType details.
            EMSSSL.SetCertificateStoreType(EMSSSLStoreType.EMSSSL_STORE_TYPE_SYSTEM, storeInfo);
        }
        catch (Exception e)
        {
            System.Console.WriteLine(e.StackTrace);

            if (e is EMSException)
            {
                EMSException je = (EMSException)e;

                if (je.LinkedException != null)
                {
                    System.Console.WriteLine("##### Linked Exception:");
                    System.Console.WriteLine(je.LinkedException.StackTrace);
                }
            }
        }

        try
        {
            ConnectionFactory factory = new ConnectionFactory(serverUrl);

            //How can I wrap this to ignore self signed certs mistrust
            // this does not work for our issues....
            ServicePointManager.ServerCertificateValidationCallback = delegate(
                object obj, X509Certificate certificate, X509Chain chain,
                System.Net.Security.SslPolicyErrors errors)
            {
                return(true);
            };

            Connection connection = factory.CreateConnection(userName, password);

            Session session = connection.CreateSession(false, TIBCO.EMS.SessionMode.AutoAcknowledge);

            Topic topic = session.CreateTopic(topicName);

            MessageProducer publisher  = session.CreateProducer(topic);
            MessageConsumer subscriber = session.CreateConsumer(topic);

            connection.Start();

            MapMessage message = session.CreateMapMessage();
            message.SetStringProperty("field", "SSL message");

            for (int i = 0; i < 3; i++)
            {
                publisher.Send(message);
                System.Console.WriteLine("\nPublished message: " + message);

                /* read same message back */
                message = (MapMessage)subscriber.Receive();
                if (message == null)
                {
                    System.Console.WriteLine("\nCould not receive message");
                }
                else
                {
                    System.Console.WriteLine("\nReceived message: " + message);
                }

                try
                {
                    System.Threading.Thread.Sleep(1000);
                }
                catch (Exception) { }
            }

            connection.Close();
        }
        catch (EMSException e)
        {
            System.Console.WriteLine("##### Exception:" + e.Message);
            System.Console.WriteLine(e.StackTrace);

            if (e.LinkedException != null)
            {
                System.Console.WriteLine("##### Linked Exception error msg:" + e.LinkedException.Message);
                System.Console.WriteLine("##### Linked Exception:");
                System.Console.WriteLine(e.LinkedException.StackTrace);
            }
        }
    }
Пример #8
0
    public csUFOMsgProducer(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("csUFOMsgProducer SAMPLE");
        Console.WriteLine("------------------------------------------------------------------------");
        Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost"));
        Console.WriteLine("User......................... " + ((userName != null)?userName:"******"));
        Console.WriteLine("Destination.................. " + name);
        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");

            factory = new ConnectionFactory(serverUrl);

            connection = factory.CreateConnection(userName, password);

            // set the exception listener
            connection.ExceptionListener = this;

            // 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);
            MessageProducer destProd = session.CreateProducer(destination);

            // 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, new UFOCompletionListener());
                }
                else
                {
                    msgProducer.Send(destination, msg);
                }

                destProd.Send(msg);
                destProd.Send(msg, new UFOCompletionListener());
                destProd.Send(msg, (int)TIBCO.EMS.MessageDeliveryMode.Persistent, 9, 10, new UFOCompletionListener());
                destProd.Send(msg, TIBCO.EMS.MessageDeliveryMode.Persistent, 9, 10);
                destProd.Send(msg, TIBCO.EMS.MessageDeliveryMode.Persistent, 9, 10, new UFOCompletionListener());

                msgProducer.Send(destination, msg);
                msgProducer.Send(destination, msg, new UFOCompletionListener());
                msgProducer.Send(destination, msg, (int)TIBCO.EMS.MessageDeliveryMode.Persistent, 9, 10, new UFOCompletionListener());
                msgProducer.Send(destination, msg, TIBCO.EMS.MessageDeliveryMode.Persistent, 9, 10);
                msgProducer.Send(destination, msg, TIBCO.EMS.MessageDeliveryMode.Persistent, 9, 10, new UFOCompletionListener());

                Console.WriteLine("Published message: " + data[i]);
            }

            // close the connection
            connection.Close();
        }
        catch (EMSException e)
        {
            Console.Error.WriteLine("Exception in csUFOMsgProducer: " + e.Message);
            Console.Error.WriteLine(e.StackTrace);
            Environment.Exit(-1);
        }
    }
Пример #9
0
    public csMsgProducer(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

        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("Message Text................. ");

        for (int i = 0; i < data.Count; i++)
        {
            Console.WriteLine(data[i]);
        }
        Console.WriteLine("------------------------------------------------------------------------\n");

        try
        {
            BytesMessage 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);

            // publish messages
            for (i = 0; i < data.Count; i++)
            {
                // create text message
                //msg = session.CreateTextMessage();
                msg = session.CreateBytesMessage();

                // set message text
                //msg.Text = (String) data[i];
                msg.WriteBoolean(false);
                msg.WriteChar('a');
                msg.WriteShort(289);
                msg.WriteInt(System.Int32.MinValue);
                msg.WriteLong(10000111121);
                msg.WriteFloat((float)-2.23);
                msg.WriteDouble(-1.2345678);

                // publish message
                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);
        }
    }
Пример #10
0
    public emsSSLSampleClient(string[] args)
    {
        if (topicName == null)
        {
            System.Console.WriteLine("Error: must specify topic name");
            usage();
        }

        System.Console.WriteLine("Global SSL parameters sample with Microsoft Certificate Store.");

        try
        {
            EMSSSLSystemStoreInfo storeInfo = new EMSSSLSystemStoreInfo();
            //EMSSSLFileStoreInfo storeInfo = new EMSSSLFileStoreInfo();

            // set trace for client-side operations, loading of certificates
            // and other
            if (ssl_trace)
            {
                EMSSSL.SetClientTracer(new System.IO.StreamWriter(System.Console.OpenStandardError()));
            }

            // set target host name in the sertificate if specified
            if (ssl_target_hostname != null)
            {
                EMSSSL.SetTargetHostName(ssl_target_hostname);
            }

            if (ssl_cert_store_location != null)
            {
                if (ssl_cert_store_location.Equals("currentuser"))
                {
                    storeInfo.SetCertificateStoreLocation(StoreLocation.CurrentUser);
                }
                else if (ssl_cert_store_location.Equals("localmachine"))
                {
                    storeInfo.SetCertificateStoreLocation(StoreLocation.LocalMachine);
                }
            }

            if (ssl_cert_store_name != null)
            {
                storeInfo.SetCertificateStoreName(ssl_cert_store_name);
            }
            if (ssl_cert_name != null)
            {
                storeInfo.SetCertificateNameAsFullSubjectDN(ssl_cert_name);
            }

            EMSSSL.SetCertificateStoreType(EMSSSLStoreType.EMSSSL_STORE_TYPE_SYSTEM, storeInfo);
        }
        catch (Exception e)
        {
            System.Console.WriteLine(e.StackTrace);

            if (e is EMSException)
            {
                EMSException je = (EMSException)e;

                if (je.LinkedException != null)
                {
                    System.Console.WriteLine("##### Linked Exception:");
                    System.Console.WriteLine(je.LinkedException.StackTrace);
                }
            }
            //System.Environment.Exit(-1);
        }

        try
        {
            ConnectionFactory factory = new ConnectionFactory(serverUrl);
            //factory.SetSSLTrace(true);
            factory.SetConnAttemptCount(1);
            factory.SetConnAttemptDelay(1000);
            factory.SetConnAttemptTimeout(1000);

            Connection connection = factory.CreateConnection(userName, password);

            Session session = connection.CreateSession(false, TIBCO.EMS.SessionMode.AutoAcknowledge);

            Topic topic = session.CreateTopic(topicName);

            MessageProducer publisher  = session.CreateProducer(topic);
            MessageConsumer subscriber = session.CreateConsumer(topic);

            connection.Start();

            MapMessage message = session.CreateMapMessage();
            message.SetStringProperty("field", "SSL message");

            for (int i = 0; i < 3; i++)
            {
                publisher.Send(message);
                System.Console.WriteLine("\nPublished message: " + message);

                /* read same message back */
                message = (MapMessage)subscriber.Receive();
                if (message == null)
                {
                    System.Console.WriteLine("\nCould not receive message");
                }
                else
                {
                    System.Console.WriteLine("\nReceived message: " + message);
                }

                try
                {
                    System.Threading.Thread.Sleep(1000);
                }
                catch (Exception) { }
            }

            connection.Close();
        }
        catch (EMSException e)
        {
            System.Console.WriteLine("##### Exception Connect:" + e.Message);
            System.Console.WriteLine(e.StackTrace);

            if (e.LinkedException != null)
            {
                System.Console.WriteLine("##### Linked Exception error msg:" + e.LinkedException.Message);
                System.Console.WriteLine("##### Linked Exception:");
                System.Console.WriteLine(e.LinkedException.StackTrace);
            }
            //System.Environment.Exit(-1);
        }
    }
Пример #11
0
    public emsSSLGlobal(String[] args)
    {
        parseArgs(args);

        if (topicName == null)
        {
            System.Console.WriteLine("Error: must specify topic name");
            usage();
        }

        System.Console.WriteLine("Global SSL parameters sample.");

        try {
            EMSSSLFileStoreInfo storeInfo = new EMSSSLFileStoreInfo();

            // set trace for client-side operations, loading of certificates
            // and other
            if (ssl_trace)
            {
                EMSSSL.SetClientTracer(new System.IO.StreamWriter(System.Console.OpenStandardError()));
            }


            // set trusted certificates if specified
            int s = ssl_trusted.Count;
            for (int i = 0; i < s; i++)
            {
                String cert = (String)ssl_trusted[i];
                storeInfo.SetSSLTrustedCertificate(cert);
            }

            // set target host name in the sertificate if specified
            if (ssl_target_hostname != null)
            {
                EMSSSL.SetTargetHostName(ssl_target_hostname);
            }

            // only pkcs12 or pfx files are supported.
            if (ssl_identity != null)
            {
                if (ssl_password == null)
                {
                    System.Console.WriteLine("Error: must specify -ssl_password if identity is set");
                    System.Environment.Exit(-1);
                }
                storeInfo.SetSSLClientIdentity(ssl_identity);
                storeInfo.SetSSLPassword(ssl_password.ToCharArray());
            }

            EMSSSL.SetCertificateStoreType(EMSSSLStoreType.EMSSSL_STORE_TYPE_FILE, storeInfo);
        }
        catch (Exception e)
        {
            System.Console.WriteLine(e.StackTrace);

            if (e is EMSException)
            {
                EMSException je = (EMSException)e;

                if (je.LinkedException != null)
                {
                    System.Console.WriteLine("##### Linked Exception:");
                    System.Console.WriteLine(je.LinkedException.StackTrace);
                }
            }
            System.Environment.Exit(-1);
        }

        try
        {
            ConnectionFactory factory = new ConnectionFactory(serverUrl);

            Connection connection = factory.CreateConnection(userName, password);

            Session session = connection.CreateSession(false, TIBCO.EMS.SessionMode.AutoAcknowledge);

            Topic topic = session.CreateTopic(topicName);

            MessageProducer publisher  = session.CreateProducer(topic);
            MessageConsumer subscriber = session.CreateConsumer(topic);

            connection.Start();

            MapMessage message = session.CreateMapMessage();
            message.SetStringProperty("field", "SSL message");

            for (int i = 0; i < 3; i++)
            {
                publisher.Send(message);
                System.Console.WriteLine("\nPublished message: " + message);

                /* read same message back */
                message = (MapMessage)subscriber.Receive();
                if (message == null)
                {
                    System.Console.WriteLine("\nCould not receive message");
                }
                else
                {
                    System.Console.WriteLine("\nReceived message: " + message);
                }

                try {
                    System.Threading.Thread.Sleep(1000);
                }
                catch (Exception) {}
            }

            connection.Close();
        }
        catch (EMSException e)
        {
            System.Console.WriteLine("##### Exception:" + e.Message);
            System.Console.WriteLine(e.StackTrace);

            if (e.LinkedException != null)
            {
                System.Console.WriteLine("##### Linked Exception error msg:" + e.LinkedException.Message);
                System.Console.WriteLine("##### Linked Exception:");
                System.Console.WriteLine(e.LinkedException.StackTrace);
            }
            System.Environment.Exit(-1);
        }
    }
Пример #12
0
    // Main method which actually publishes all messages, checks when they all
    // have been received by the subscriber, then calculates and prints the
    // performance numbers. The delivery mode and acknowledge mode are
    // parameters to this method.
    public void DoRun(int deliveryMode, int acknowledgeMode,
                      bool warmupMode)
    {
        // we need two sessions
        publishSession   = connection.CreateSession(false, acknowledgeMode);
        subscribeSession = connection.CreateSession(false, acknowledgeMode);

        // little thread printing dots on the screen while nothing else happens
        Thread tracker = null;

        // if not yet created, create main topic and the check topic used to
        // send confirmations back from the subscriber to the publisher
        if (topic == null)
        {
            topic      = publishSession.CreateTopic("test.extensions.topic");
            checkTopic = publishSession.CreateTopic("test.extensions.check.topic");
        }

        // create the publisher and set its delivery mode
        publisher = publishSession.CreateProducer(topic);
        publisher.DeliveryMode = deliveryMode;

        // create the subscriber and set its listener
        subscriber = subscribeSession.CreateConsumer(topic);
        subscriber.MessageListener = new MyMessageListener(this, acknowledgeMode, warmupMode);

        // create publisher and subscriber to deal with the final confirmation
        // message
        checkPublisher  = subscribeSession.CreateProducer(checkTopic);
        checkSubscriber = publishSession.CreateConsumer(checkTopic);

        // will publish virtually empty message
        Message message = publishSession.CreateMessage();

        if (!warmupMode)
        {
            Console.WriteLine("");
            Console.WriteLine("Sending and Receiving " + count + " messages");
            Console.WriteLine("        delivery mode:    " + DeliveryModeName(deliveryMode));
            Console.WriteLine("        acknowledge mode: " + AcknowledgeModeName(acknowledgeMode));
        }

        // start printing dots while we run the main loop
        tracker = new Thread(new ThreadStart(this.Run));
        tracker.Start();

        long startTime = (DateTime.Now.Ticks - 621355968000000000) / 10000;

        // now publish all messages
        for (int i = 0; i < count; i++)
        {
            publisher.Send(message);
        }

        // and wait for the subscriber to receive all messages and publish the
        // confirmation message which we'll receive here. If anything goes
        // wrong we will get stuck here, but let's hope everything will be
        // fine
        checkSubscriber.Receive();

        // print performance, close all and we are done
        long endTime = (DateTime.Now.Ticks - 621355968000000000) / 10000;

        tracker.Interrupt();

        if (!warmupMode)
        {
            Console.WriteLine(" completed");

            if ((endTime - startTime) < 3000)
            {
                Console.WriteLine("**Warning**: elapsed time is too small to calculate reliable performance");
                Console.WriteLine("             numbers. You need to re-run this test with greater number");
                Console.WriteLine("             of messages. Use '-count' command-line parameter to specify");
                Console.WriteLine("             greater message count.");
            }

            Console.WriteLine(GetPerformance(startTime, endTime, count));
        }

        publishSession.Close();
        subscribeSession.Close();
    }
Пример #13
0
        public void Send <T>(T message, TimeSpan timeToLive) where T : class
        {
            if (_disposed)
            {
                throw new ObjectDisposedException("The object has been disposed");
            }

            Session session = _connection.CreateSession(true, SessionMode.SessionTransacted);

            if (session == null)
            {
                throw new EndpointException(Uri, "Unable to open session to endpoint");
            }

            Destination destination = session.CreateQueue(_queueName);

            MessageProducer producer = session.CreateProducer(destination);

            if (producer != null)
            {
                Type messageType = typeof(T);

                TextMessage textMessage = session.CreateTextMessage();

                using (MemoryStream mem = new MemoryStream())
                {
                    _serializer.Serialize(mem, message);

                    textMessage.Text = Encoding.UTF8.GetString(mem.ToArray());
                }

                if (timeToLive < TimeSpan.MaxValue)
                {
                    producer.TimeToLive = (long)timeToLive.TotalMilliseconds;
                }

                producer.DeliveryMode = _deliveryMode;

                producer.Send(textMessage);

                session.Commit();

                if (SpecialLoggers.Messages.IsInfoEnabled)
                {
                    SpecialLoggers.Messages.InfoFormat("SEND:{0}:{1}:{2}", Uri, messageType.Name, textMessage.MessageID);
                }

                if (_log.IsDebugEnabled)
                {
                    _log.DebugFormat("Sent {0} from {1} [{2}]", messageType.FullName, Uri, textMessage.MessageID);
                }

                producer.Close();
            }
            else
            {
                throw new EndpointException(Uri, "Unable to create message producer");
            }

            session.Close();
        }
Пример #14
0
    string ssl_password        = null;          // password to decrypt client identity or key file {password}


    public tibemsSSL(string[] args)
    {
        ssl_trusted.Add("C:/tibco/ems/8.3/samples/certs/server_root.cert.pem");
        ssl_target_hostname = "localhost";
        ssl_identity        = "C:/tibco/ems/8.3/samples/certs/client_identity.p12";
        ssl_password        = "******";

        if (topicName == null)
        {
            System.Console.WriteLine("Error: must specify topic name");
            //usage();
        }


        if (topicName == null)
        {
            System.Console.WriteLine("Error: must specify topic name");
        }
        System.Console.WriteLine("SSL sample.");


        // initialize SSL environment
        Hashtable environment = new Hashtable();

        try
        {
            EMSSSLFileStoreInfo storeInfo = new EMSSSLFileStoreInfo();

            // set trace for client-side operations, loading of certificates
            // and other
            if (ssl_trace)
            {
                environment.Add(EMSSSL.TRACE, true);
            }

            // set trusted certificates if specified
            int s = ssl_trusted.Count;
            for (int i = 0; i < s; i++)
            {
                String cert = (String)ssl_trusted[i];
                storeInfo.SetSSLTrustedCertificate(cert);
            }

            // set expected host name in the certificate if specified
            if (ssl_target_hostname != null)
            {
                environment.Add(EMSSSL.TARGET_HOST_NAME, ssl_target_hostname);
            }

            // only pkcs12 or pfx files are supported.
            if (ssl_identity != null)
            {
                if (ssl_password == null)
                {
                    System.Console.WriteLine("Error: must specify -ssl_password if identity is set");
                    System.Environment.Exit(-1);
                }
                storeInfo.SetSSLClientIdentity(ssl_identity);
                storeInfo.SetSSLPassword(ssl_password.ToCharArray());
            }
            environment.Add(EMSSSL.STORE_INFO, storeInfo);
            environment.Add(EMSSSL.STORE_TYPE, EMSSSLStoreType.EMSSSL_STORE_TYPE_FILE);
        }
        catch (Exception e)
        {
            System.Console.WriteLine("ERROR MSG: " + e.Message);
            System.Console.WriteLine(e.StackTrace);

            if (e is EMSException)
            {
                EMSException je = (EMSException)e;
                if (je.LinkedException != null)
                {
                    System.Console.WriteLine("Linked Exception Error Msg: " + e.Message);
                    System.Console.WriteLine("##### Linked Exception:");
                    System.Console.WriteLine(je.LinkedException.StackTrace);
                }
            }
            //System.Environment.Exit(-1);
        }

        try
        {
            ConnectionFactory factory = new ConnectionFactory(serverUrl, null, environment);

            Connection connection = factory.CreateConnection(userName, password);

            Session session = connection.CreateSession(false, TIBCO.EMS.SessionMode.AutoAcknowledge);

            Topic topic = session.CreateTopic(topicName);

            MessageProducer publisher  = session.CreateProducer(topic);
            MessageConsumer subscriber = session.CreateConsumer(topic);

            connection.Start();

            MapMessage message = session.CreateMapMessage();
            message.SetStringProperty("field", "SSL message");

            for (int i = 0; i < 3; i++)
            {
                publisher.Send(message);
                System.Console.WriteLine("\nPublished message: " + message);

                /* read same message back */

                message = (MapMessage)subscriber.Receive();
                if (message == null)
                {
                    System.Console.WriteLine("\nCould not receive message");
                }
                else
                {
                    System.Console.WriteLine("\nReceived message: " + message);
                }

                try
                {
                    System.Threading.Thread.Sleep(1000);
                }
                catch (Exception) { }
            }

            connection.Close();
        }
        catch (EMSException e)
        {
            System.Console.WriteLine("ERROR MSG: " + e.Message);
            System.Console.WriteLine(e.StackTrace);

            if (e.LinkedException != null)
            {
                System.Console.WriteLine("Linked Exception Error Msg: " + e.Message);
                System.Console.WriteLine("##### Linked Exception:");
                System.Console.WriteLine(e.LinkedException.StackTrace);
            }
            //System.Environment.Exit(-1);
        }
    }
Пример #15
0
    public csSelector(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("csSelector SAMPLE");
        Console.WriteLine("------------------------------------------------------------------------");
        Console.WriteLine("Server....................... " + ((serverUrl != null)?serverUrl:"localhost"));
        Console.WriteLine("User......................... " + ((userName != null)?userName:"******"));
        Console.WriteLine("Queue........................ " + queueName);
        Console.WriteLine("------------------------------------------------------------------------\n");


        if (!noselector)
        {
            Console.WriteLine("\n*** Also try to run this sample with the -noselector");
            Console.WriteLine("*** option to see the difference it makes.");
        }

        try {
            ConnectionFactory factory = new TIBCO.EMS.ConnectionFactory(serverUrl);

            Connection connection = factory.CreateConnection(userName, password);

            Session receive_session = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);
            Session send_session    = connection.CreateSession(false, Session.AUTO_ACKNOWLEDGE);

            Queue queue = send_session.CreateQueue(queueName);

            // Start the connection so we can drain the queue and then proceed.
            connection.Start();

            // drain the queue
            MessageConsumer receiver = receive_session.CreateConsumer(queue);

            int drain_count = 0;
            Console.WriteLine("\nDraining the queue " + queueName);

            // read queue until empty
            while (receiver.Receive(1000) != null)
            {
                drain_count++;
            }
            Console.WriteLine("Drained " + drain_count + " messages from the queue");

            // close receiver to prevent any queue messages to be delivered
            receiver.Close();

            // create receivers with selectors
            Console.WriteLine("");
            if (!noselector)
            {
                Console.WriteLine("Creating receivers with selectors:\n");
            }
            else
            {
                Console.WriteLine("Creating receivers without selectors:\n");
            }
            Thread.Sleep(500);

            int receiver_count = 3;
            for (int i = 0; i < receiver_count; i++)
            {
                String selector = null;

                if (!noselector)
                {
                    selector = "count >= " + (i * 4) + " AND count < " + (i * 4 + 4);
                }

                receiver = receive_session.CreateConsumer(queue, selector);

                if (!noselector)
                {
                    Console.WriteLine("Created receiver " + i + " with selector: \"" + selector + "\"");
                }
                else
                {
                    Console.WriteLine("Created receiver " + i);
                }

                receiver.MessageListener = new MyMessageListener(i);
                Thread.Sleep(500);
            }

            // create sender
            MessageProducer sender = send_session.CreateProducer(queue);

            Message message = null;

            int message_number = 0;

            // send 12 messages into queue
            Console.WriteLine("");
            Console.WriteLine("Sending 12 messages into the queue:\n");

            Thread.Sleep(200);

            for (int i = 0; i < 12; i++)
            {
                message = send_session.CreateMessage();
                message.SetIntProperty("count", message_number);
                sender.Send(message);
                Thread.Sleep(500);
                message_number++;
            }

            // wait for some time while all messages received
            Thread.Sleep(1000);

            connection.Close();
        } catch (EMSException e) {
            Console.Error.WriteLine("Exception in csSelector: " + e.Message);
            Console.Error.WriteLine(e.StackTrace);
            Environment.Exit(0);
        } catch (ThreadInterruptedException e) {
            Console.Error.WriteLine("Exception in csSelector: " + e.Message);
            Console.Error.WriteLine(e.StackTrace);
            Environment.Exit(0);
        }
    }
Пример #16
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);
        }
    }
Пример #17
0
 public void Send(Message message)
 {
     nativeMessageProducer.Send(message);
 }
Пример #18
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);
        }
    }