static private void SetRemConnectionProperties(IConnectionFactory cf, Env.ConnVariables conn) { 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); Console.WriteLine("Connection Cipher is set to {0}", conn.cipher_suite); Console.WriteLine("Key Repository is set to {0}", conn.key_repository); 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); } }
static public void SetConnectionProperties(IConnectionFactory cf, Env env) { Env.ConnVariables conn = env.Conn; string ccdtURL = checkForCCDT(); if (null != ccdtURL) { Console.WriteLine("CCDT Environment setting found"); cf.SetStringProperty(XMSC.WMQ_CCDTURL, ccdtURL); } else { if (env.NumberOfConnections() > 1) { Console.WriteLine("There are {0} connections", env.NumberOfConnections()); cf.SetStringProperty(XMSC.WMQ_CONNECTION_NAME_LIST, env.BuildConnectionString()); Console.WriteLine("Connection string is {0}", env.BuildConnectionString()); } else { 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); } SetRemConnectionProperties(cf, conn); }
static public void SetConnectionProperties(IConnectionFactory cf, Env.ConnVariables conn) { cf.SetStringProperty(XMSC.WMQ_HOST_NAME, conn.host); Console.WriteLine("hostName is set {0, -20 }", conn.host); cf.SetIntProperty(XMSC.WMQ_PORT, conn.port); SetRemConnectionProperties(cf, conn); }
void SendMessage() { XMSFactoryFactory factoryFactory; IConnectionFactory cf; IConnection connectionWMQ; ISession sessionWMQ; IDestination destination; 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); // 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.CreateTopic(conn.topic_name); destination.SetIntProperty(XMSC.WMQ_TARGET_CLIENT, XMSC.WMQ_TARGET_DEST_MQ); Console.WriteLine("Destination created"); // Create producer producer = sessionWMQ.CreateProducer(destination); Console.WriteLine("Publisher created"); // Start the connection to receive messages. connectionWMQ.Start(); Console.WriteLine("Connection started"); // Create a text message and send it. textMessage = sessionWMQ.CreateTextMessage(); textMessage.Text = xmsJson.toJsonString(); producer.Send(textMessage); Console.WriteLine("Message published"); // Cleanup producer.Close(); destination.Dispose(); sessionWMQ.Dispose(); connectionWMQ.Close(); }
private void ReceiveMessagesFromEndpoint(IConnectionFactory cf, Env.ConnVariables cv) { IConnection connectionWMQ; ISession sessionWMQ; IDestination destination; IMessageConsumer consumer; ITextMessage textMessage; // 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(cv.queue_name); Console.WriteLine("Destination created"); // Create consumer consumer = sessionWMQ.CreateConsumer(destination); Console.WriteLine("Consumer created"); // Start the connection to receive messages. connectionWMQ.Start(); Console.WriteLine("Connection started"); Console.WriteLine("Receive message: " + TIMEOUTTIME / 1000 + " seconds wait time"); // Wait for 30 seconds for messages. Exit if no message by then while (SimpleConsumer.keepRunning) { textMessage = (ITextMessage)consumer.Receive(TIMEOUTTIME); if (textMessage != null) { Console.WriteLine("Message received."); Console.Write(textMessage); Console.WriteLine("\n"); } else { Console.WriteLine("Wait timed out."); SimpleConsumer.keepRunning = false; } } // Cleanup consumer.Close(); destination.Dispose(); sessionWMQ.Dispose(); connectionWMQ.Close(); }
static public void SetConnectionProperties(IConnectionFactory cf, Env.ConnVariables conn) { string ccdtURL = checkForCCDT(); if (null != ccdtURL) { Console.WriteLine("CCDT Environment setting found"); cf.SetStringProperty(XMSC.WMQ_CCDTURL, ccdtURL); } else { 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); } SetRemConnectionProperties(cf, conn); }
static public void SetConnectionProperties(IConnectionFactory cf, Env env) { Env.ConnVariables conn = env.Conn; if (env.NumberOfConnections() > 1) { Console.WriteLine("There are {0} connections", env.NumberOfConnections()); cf.SetStringProperty(XMSC.WMQ_CONNECTION_NAME_LIST, env.BuildConnectionString()); Console.WriteLine("Connection string is {0}", env.BuildConnectionString()); } else { cf.SetStringProperty(XMSC.WMQ_HOST_NAME, conn.host); Console.WriteLine("hostName is set {0, -20 }", conn.host); cf.SetIntProperty(XMSC.WMQ_PORT, conn.port); } SetRemConnectionProperties(cf, conn); }
void ReceiveMessages() { XMSFactoryFactory factoryFactory; IConnectionFactory cf; IConnection connectionWMQ; ISession sessionWMQ; IDestination destination; IMessageConsumer consumer; 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); // 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); Console.WriteLine("Destination created"); // Create consumer consumer = sessionWMQ.CreateConsumer(destination); Console.WriteLine("Consumer created"); // Start the connection to receive messages. connectionWMQ.Start(); Console.WriteLine("Connection started"); Console.WriteLine("Receive message: " + TIMEOUTTIME / 1000 + " seconds wait time"); // Wait for 30 seconds for messages. Exit if no message by then while (SimpleResponse.keepRunning) { textMessage = (ITextMessage)consumer.Receive(TIMEOUTTIME); if (textMessage != null) { Console.WriteLine("Message received."); Console.Write(textMessage); Console.WriteLine("\n"); replyToMessage(textMessage, sessionWMQ); } else { Console.WriteLine("Wait timed out."); } } // Cleanup consumer.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(); }