public static String getCorrFilter(String s)
 {
     return(JsonMessage.AsHexString(JsonMessage.AsBytes(s)).Replace("-", "").Substring(0, 2 * CO_ID_LENGTH));
 }
        void SendMessage()
        {
            XMSFactoryFactory  factoryFactory;
            IConnectionFactory cf;
            IConnection        connectionWMQ;
            ISession           sessionWMQ;
            IDestination       destination;
            IDestination       temporaryDestination;
            IMessageProducer   producer;
            ITextMessage       textMessage;

            // Get an instance of factory.
            factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);

            // Create WMQ Connection Factory.
            cf = factoryFactory.CreateConnectionFactory();

            // Set the properties
            cf.SetStringProperty(XMSC.WMQ_HOST_NAME, conn.host);
            Console.WriteLine("hostName is set {0, -20 }", conn.host);
            cf.SetIntProperty(XMSC.WMQ_PORT, conn.port);
            cf.SetStringProperty(XMSC.WMQ_CHANNEL, conn.channel);
            if (conn.key_repository != null && (conn.key_repository.Contains("*SYSTEM") || conn.key_repository.Contains("*USER")))
            {
                cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT);
            }
            else
            {
                cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT_UNMANAGED);
            }
            cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, conn.qmgr);
            cf.SetStringProperty(XMSC.USERID, conn.app_user);
            cf.SetStringProperty(XMSC.PASSWORD, conn.app_password);
            cf.SetStringProperty(XMSC.WMQ_TEMPORARY_MODEL, conn.model_queue_name);
            if (conn.key_repository != null && conn.cipher_suite != null)
            {
                cf.SetStringProperty(XMSC.WMQ_SSL_KEY_REPOSITORY, conn.key_repository);
            }
            if (conn.cipher_suite != null)
            {
                cf.SetStringProperty(XMSC.WMQ_SSL_CIPHER_SPEC, conn.cipher_suite);
            }

            // Create connection.
            connectionWMQ = cf.CreateConnection();
            Console.WriteLine("Connection created");

            // Create session
            sessionWMQ = connectionWMQ.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
            Console.WriteLine("Session created");

            // Create destination
            destination = sessionWMQ.CreateQueue(conn.queue_name);
            destination.SetIntProperty(XMSC.WMQ_TARGET_CLIENT, XMSC.WMQ_TARGET_DEST_MQ);
            Console.WriteLine("Destination created");

            // Create producer
            producer = sessionWMQ.CreateProducer(destination);
            Console.WriteLine("Producer created");

            // Start the connection to receive messages.
            connectionWMQ.Start();
            Console.WriteLine("Connection started");

            // Create a text message and send it.
            textMessage = sessionWMQ.CreateTextMessage();

            String corrID = xmsJson.correlationID;

            textMessage.Text = xmsJson.toJsonString();
            //***disable for correl id by using message id
            textMessage.JMSCorrelationID = corrID;
            textMessage.JMSExpiration    = 900000;
            temporaryDestination         = sessionWMQ.CreateTemporaryQueue();
            textMessage.JMSReplyTo       = temporaryDestination;

            producer.Send(textMessage);
            Console.WriteLine("Message sent");
            Console.WriteLine(textMessage.JMSCorrelationID);
            Console.WriteLine(corrID);
            String str      = textMessage.JMSMessageID;
            String selector = "JMSCorrelationID='ID:" + JsonMessage.getCorrFilter(corrID) + "'";


            Console.WriteLine(selector);

            IMessageConsumer consumer        = sessionWMQ.CreateConsumer(temporaryDestination, selector);
            ITextMessage     responseMessage = (ITextMessage)consumer.Receive(TIMEOUTTIME);

            if (responseMessage != null)
            {
                Console.WriteLine("Message received.");
                Console.Write(responseMessage);
                Console.WriteLine("\n");
            }
            else
            {
                Console.WriteLine("Wait timed out.");
            }


            // Cleanup
            producer.Close();
            destination.Dispose();
            sessionWMQ.Dispose();
            connectionWMQ.Close();
        }
        void SendMessage()
        {
            XMSFactoryFactory  factoryFactory;
            IConnectionFactory cf;
            IConnection        connectionWMQ;
            ISession           sessionWMQ;
            IDestination       destination;
            IDestination       temporaryDestination;
            IMessageProducer   producer;
            ITextMessage       textMessage;

            Env.ConnVariables conn = env.Conn;

            // Get an instance of factory.
            factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);

            // Create WMQ Connection Factory.
            cf = factoryFactory.CreateConnectionFactory();

            // Set the properties
            ConnectionPropertyBuilder.SetConnectionProperties(cf, env);
            cf.SetStringProperty(XMSC.WMQ_TEMPORARY_MODEL, conn.model_queue_name);

            // Create connection.
            connectionWMQ = cf.CreateConnection();
            Console.WriteLine("Connection created");

            // Create session
            sessionWMQ = connectionWMQ.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
            Console.WriteLine("Session created");

            // Create destination
            destination = sessionWMQ.CreateQueue(conn.queue_name);
            destination.SetIntProperty(XMSC.WMQ_TARGET_CLIENT, XMSC.WMQ_TARGET_DEST_MQ);
            Console.WriteLine("Destination created");

            // Create producer
            producer = sessionWMQ.CreateProducer(destination);
            Console.WriteLine("Producer created");

            // Start the connection to receive messages.
            connectionWMQ.Start();
            Console.WriteLine("Connection started");

            // Create a text message and send it.
            textMessage = sessionWMQ.CreateTextMessage();

            String corrID = xmsJson.correlationID;

            textMessage.Text = xmsJson.toJsonString();
            //***disable for correl id by using message id
            textMessage.JMSCorrelationID = corrID;
            textMessage.JMSExpiration    = 900000;
            temporaryDestination         = sessionWMQ.CreateTemporaryQueue();
            textMessage.JMSReplyTo       = temporaryDestination;

            producer.Send(textMessage);
            Console.WriteLine("Message sent");
            Console.WriteLine(textMessage.JMSCorrelationID);
            Console.WriteLine(corrID);
            String str      = textMessage.JMSMessageID;
            String selector = "JMSCorrelationID='ID:" + JsonMessage.getCorrFilter(corrID) + "'";


            Console.WriteLine(selector);

            IMessageConsumer consumer        = sessionWMQ.CreateConsumer(temporaryDestination, selector);
            ITextMessage     responseMessage = (ITextMessage)consumer.Receive(TIMEOUTTIME);

            if (responseMessage != null)
            {
                Console.WriteLine("Message received.");
                Console.Write(responseMessage);
                Console.WriteLine("\n");
            }
            else
            {
                Console.WriteLine("Wait timed out.");
            }


            // Cleanup
            producer.Close();
            destination.Dispose();
            sessionWMQ.Dispose();
            connectionWMQ.Close();
        }