public void TerminateConnections() { if (_mqMessageConsumer != null) { try { _mqMessageConsumer.Close(); _mqMessageConsumer.Dispose(); } catch (Exception exception) { FdrCommon.LogEvent(exception, EventLogEntryType.Error); } } if (_mqDestination != null) { _mqDestination.Dispose(); _mqDestination = null; } if (_mqConnection != null) { _mqConnection.Close(); _mqConnection.Dispose(); } if (_mqSession != null) { _mqSession.Close(); _mqSession.Dispose(); } _connectionFactory = null; _xffReadFactory = null; }
public void ListenForCbcRequests() { try{ _xffReadFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); _connectionFactory = _xffReadFactory.CreateConnectionFactory(); _connectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, CBCApplicationConfigurationdetails.RequestConnection); _connectionFactory.SetIntProperty(XMSC.WMQ_PORT, CBCApplicationConfigurationdetails.RequestPort); _connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, CBCApplicationConfigurationdetails.RequestChannel); _connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT); _connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, CBCApplicationConfigurationdetails.RequestManger); _connectionFactory.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1); _connectionFactory.SetStringProperty(XMSC.WMQ_PROVIDER_VERSION, MQConfigurationSettings.WMQ_PROVIDER_VERSION); _mqConnection = _connectionFactory.CreateConnection(); _mqSession = _mqConnection.CreateSession(false, AcknowledgeMode.AutoAcknowledge); _mqDestination = _mqSession.CreateQueue(string.Format("queue://{0}/{1}", CBCApplicationConfigurationdetails.RequestManger, CBCApplicationConfigurationdetails.RequestQueueName)); _mqMessageConsumer = _mqSession.CreateConsumer(_mqDestination); MessageListener ml = OnMessage; _mqMessageConsumer.MessageListener = ml; _mqConnection.Start(); //Thread.Sleep(100000); } catch (Exception exception) { FdrCommon.LogEvent(exception, EventLogEntryType.Error); } }
public void RegisterListener() { try { XMSFactoryFactory xff = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); IConnectionFactory cf = xff.CreateConnectionFactory(); cf.SetStringProperty(XMSC.WMQ_HOST_NAME, "localhost"); cf.SetIntProperty(XMSC.WMQ_PORT, 1414); cf.SetStringProperty(XMSC.WMQ_CHANNEL, "MY.SVRCONN"); cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT); cf.SetStringProperty(XMSC.USERID, "userid"); cf.SetStringProperty(XMSC.PASSWORD, "password"); cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "QM1"); IConnection conn = cf.CreateConnection(); Console.WriteLine("connection created"); ISession sess = conn.CreateSession(false, AcknowledgeMode.AutoAcknowledge); IDestination dest = sess.CreateQueue(queue); IMessageConsumer consumer = sess.CreateConsumer(dest); MessageListener ml = new MessageListener(onMessage); consumer.MessageListener = ml; conn.Start(); Console.WriteLine("Consumer started"); } catch (Exception ex) { Console.WriteLine(ex); } }
private static IConnection CreateConnection() { // Create the connection factories factory var factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); // Use the connection factories factory to create a connection factory var cf = factoryFactory.CreateConnectionFactory(); // Set the properties cf.SetStringProperty(XMSC.WMQ_HOST_NAME, "localhost"); cf.SetIntProperty(XMSC.WMQ_PORT, 1415); cf.SetStringProperty(XMSC.WMQ_CHANNEL, "NewOne"); cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT); cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "Test2"); var clientId = String.Format("NServiceBus-{0}", Thread.CurrentThread.ManagedThreadId); cf.SetStringProperty(XMSC.CLIENT_ID, clientId); var connection = cf.CreateConnection(); connection.Start(); return(connection); }
public IConnectionFactory GetConnectionFactory(int connectionType) { lock (connectionFactoryLock) { var factoryFactory = XMSFactoryFactory.GetInstance(connectionType); return(factoryFactory.CreateConnectionFactory()); } }
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(); }
public ConnectionFactory(WebSphereMqSettings settings) { // Create the connection factories factory var factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); // Use the connection factories factory to create a connection factory connectionFactory = factoryFactory.CreateConnectionFactory(); // Set the properties connectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, settings.Hostname); connectionFactory.SetIntProperty(XMSC.WMQ_PORT, settings.Port); connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, settings.Channel); connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT); connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, settings.QueueManager); }
public IConnectionFactory CreateMQConnectionFactoryWMQ(String hostName, int portNumber, String channelName, String queueManagerName) { XMSFactoryFactory factory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); IConnectionFactory cf = factory.CreateConnectionFactory(); cf.SetStringProperty(XMSC.WMQ_HOST_NAME, hostName); cf.SetIntProperty(XMSC.WMQ_PORT, portNumber); // For .NET only (Java JMS is okay using WMQ_CM_CLIENT): managed connections to WMQ (WMQ_CM_CLIENT) will not support SSL connections, but these might be supported by using an unmanaged connection (WMQ_CM_CLIENT_UNMANAGED). Refer to the WebSphere MQ Using .NET manual for accurate information. // WebSphere MQ configures a CHLAUTH record by default in WebSphere MQ Version 7.1 and later that blocks all MQ admins from connecting as a client to the queue manager. The following error in the MQ error logs would be seen for this scenario: // by default is XMSC.WMQ_CM_CLIENT; however, connection exception due to code 2035 cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT_UNMANAGED); cf.SetStringProperty(XMSC.WMQ_CHANNEL, channelName); cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, queueManagerName); return(cf); }
public static void SendMessageToQueue(QueueInfo queueInfo) { try { var xmsFactoryInstance = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); var connectionFactory = xmsFactoryInstance.CreateConnectionFactory(); connectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, queueInfo.HostName); connectionFactory.SetIntProperty(XMSC.WMQ_PORT, queueInfo.Port); connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, queueInfo.Channel); connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT); connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, queueInfo.NoManager); connectionFactory.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1); var connection = connectionFactory.CreateConnection(); using (var connectionSession = connection.CreateSession(false, AcknowledgeMode.AutoAcknowledge)) { using (var destination = connectionSession.CreateQueue(queueInfo.QueueConnection)) { destination.SetIntProperty(XMSC.DELIVERY_MODE, MQConfigurationSettings.DELIVERY_MODE); destination.SetIntProperty(XMSC.WMQ_TARGET_CLIENT, XMSC.WMQ_TARGET_DEST_MQ); destination.SetBooleanProperty(XMSC.WMQ_MQMD_READ_ENABLED, true); destination.SetBooleanProperty(XMSC.WMQ_MQMD_WRITE_ENABLED, true); using (var producer = connectionSession.CreateProducer(destination)) { var textMessage = connectionSession.CreateTextMessage(queueInfo.Message); textMessage.SetIntProperty(XMSC.JMS_IBM_ENCODING, MQConfigurationSettings.JMS_IBM_ENCODING); textMessage.SetIntProperty(XMSC.JMS_IBM_CHARACTER_SET, MQConfigurationSettings.JMS_IBM_CHARACTER_SET); if (!string.IsNullOrEmpty(queueInfo.CorrelationId)) { textMessage.JMSCorrelationID = queueInfo.CorrelationId; } producer.Send(textMessage); producer.Close(); connectionSession.Close(); connectionSession.Dispose(); } } } } catch (Exception exception) { FdrCommon.LogEvent(exception, EventLogEntryType.Error); } }
private static void RespondToCbc(string qMessage, string correlationId) { try { var xmsFactoryInstance = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); var connectionFactory = xmsFactoryInstance.CreateConnectionFactory(); connectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, MQConfigurationSettings.MNE_Equire_OUT_QConnection); connectionFactory.SetIntProperty(XMSC.WMQ_PORT, MQConfigurationSettings.MNE_Equire_OUT_PortNumber); connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, MQConfigurationSettings.MNE_Equire_OUT_QChannelName); connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT); connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, string.Empty); connectionFactory.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1); //_connectionFactory.SetStringProperty(XMSC.WMQ_MESSAGE_BODY, XMSC.messa); var connection = connectionFactory.CreateConnection(); var connectionSession = connection.CreateSession(false, AcknowledgeMode.AutoAcknowledge); var destination = connectionSession.CreateQueue(string.Format("queue://{0}/{1}", string.Empty, MQConfigurationSettings.CBC_Declaration_OUT_QName)); destination.SetIntProperty(XMSC.DELIVERY_MODE, MQConfigurationSettings.DELIVERY_MODE); destination.SetIntProperty(XMSC.WMQ_TARGET_CLIENT, XMSC.WMQ_TARGET_DEST_MQ); destination.SetBooleanProperty(XMSC.WMQ_MQMD_READ_ENABLED, true); destination.SetBooleanProperty(XMSC.WMQ_MQMD_WRITE_ENABLED, true); var producer = connectionSession.CreateProducer(destination); var textMessage = connectionSession.CreateTextMessage(qMessage); textMessage.SetIntProperty(XMSC.JMS_IBM_ENCODING, MQConfigurationSettings.JMS_IBM_ENCODING); textMessage.SetIntProperty(XMSC.JMS_IBM_CHARACTER_SET, MQConfigurationSettings.JMS_IBM_CHARACTER_SET); textMessage.JMSCorrelationID = correlationId; producer.Send(textMessage); producer.Close(); producer.Dispose(); destination.Dispose(); connectionSession.Close(); connectionSession.Dispose(); } catch (Exception exception) { FdrCommon.LogEvent(exception, EventLogEntryType.Error); } }
public ConnectionFactory(WebSphereMqSettings settings) { // Create the connection factories factory var factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); // Use the connection factories factory to create a connection factory connectionFactory = factoryFactory.CreateConnectionFactory(); // Set the properties connectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, settings.Hostname); connectionFactory.SetIntProperty(XMSC.WMQ_PORT, settings.Port); connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, settings.Channel); connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT_UNMANAGED); connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, settings.QueueManager); connectionFactory.SetStringProperty(XMSC.WMQ_SSL_CIPHER_SPEC, settings.SslCipherSpec); connectionFactory.SetStringProperty(XMSC.WMQ_SSL_KEY_REPOSITORY, settings.SslKeyRepository); connectionFactory.SetStringProperty(XMSC.WMQ_SSL_PEER_NAME, settings.SslPeerName); }
/// <summary> /// Create a connection to the Queue Manager /// </summary> /// <returns></returns> private IConnection CreateConnection() { // Get an instance of factory. var factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); // Create WMQ Connection Factory. var cf = factoryFactory.CreateConnectionFactory(); // Set the properties cf.SetStringProperty(XMSC.WMQ_HOST_NAME, (String)properties[XMSC.WMQ_HOST_NAME]); cf.SetIntProperty(XMSC.WMQ_PORT, Convert.ToInt32(properties[XMSC.WMQ_PORT])); cf.SetStringProperty(XMSC.WMQ_CHANNEL, (String)properties[XMSC.WMQ_CHANNEL]); cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT); cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, (String)properties[XMSC.WMQ_QUEUE_MANAGER]); var shareCnv = Convert.ToBoolean(properties["ShareCnv"]); if (!shareCnv) { cf.SetIntProperty(XMSC.WMQ_SHARE_CONV_ALLOWED, XMSC.WMQ_SHARE_CONV_ALLOWED_NO); } return(cf.CreateConnection()); }
public DefaultIBMMQPersistentConnection(ILogger <DefaultIBMMQPersistentConnection> logger, IDictionary <string, string> config) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _topic = config["topic"]; // Get an instance of factory. var _factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); // Create WMQ Connection Factory. _connectionFactory = _factoryFactory.CreateConnectionFactory(); _connectionFactory.SetStringProperty(XMSC.USERID, config["userid"]); _connectionFactory.SetStringProperty(XMSC.PASSWORD, config["password"]); _connectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, config["host"]); _connectionFactory.SetIntProperty(XMSC.WMQ_PORT, int.Parse(config["port"])); _connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, config["channel"]); _connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, config["qmgr"]); _connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT); }
public void ListenMasterLocalFilesRequests() { _xffReadFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); _connectionFactory = _xffReadFactory.CreateConnectionFactory(); _connectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, LMApplicationConfigurationdetails.RequestConnection); _connectionFactory.SetIntProperty(XMSC.WMQ_PORT, LMApplicationConfigurationdetails.RequestPort); _connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, LMApplicationConfigurationdetails.RequestChannel); _connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT); _connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, LMApplicationConfigurationdetails.RequestManger); _connectionFactory.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1); _connectionFactory.SetStringProperty(XMSC.WMQ_PROVIDER_VERSION, MQConfigurationSettings.WMQ_PROVIDER_VERSION); _mqConnection = _connectionFactory.CreateConnection(); _newSesstion = _mqConnection.CreateSession(false, AcknowledgeMode.AutoAcknowledge); _mqDestination = _newSesstion.CreateQueue(string.Format("queue://{0}/{1}", LMApplicationConfigurationdetails.RequestManger, LMApplicationConfigurationdetails.RequestQueueName)); _mqMessageConsumer = _newSesstion.CreateConsumer(_mqDestination); MessageListener ml = OnFilesReceived; _mqMessageConsumer.MessageListener = ml; _mqConnection.Start(); //Thread.Sleep(int.MaxValue); }
public void Setup() { XMSFactoryFactory xff = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); IConnectionFactory cf = xff.CreateConnectionFactory(); cf.SetStringProperty(XMSC.WMQ_HOST_NAME, "localhost"); cf.SetIntProperty(XMSC.WMQ_PORT, 1414); cf.SetStringProperty(XMSC.WMQ_CHANNEL, "CLIENT"); cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT); cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, "QM_LOCAL"); cf.SetIntProperty(XMSC.WMQ_BROKER_VERSION, XMSC.WMQ_BROKER_V1); IConnection conn = cf.CreateConnection(); Console.WriteLine("connection created"); ISession sess = conn.CreateSession(false, AcknowledgeMode.AutoAcknowledge); IDestination dest = sess.CreateQueue("queue://q"); IMessageConsumer consumer = sess.CreateConsumer(dest); MessageListener ml = new MessageListener(OnMessage); consumer.MessageListener = ml; conn.Start(); Console.WriteLine("Consumer started"); }
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(); }
void SendMessage() { XMSFactoryFactory factoryFactory; IConnectionFactory cf; IConnection connectionWMQ; ISession sessionWMQ; IDestination destination; 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); 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.CreateTopic(conn.topic_name); 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(); }
/// <summary> /// Method to connect to queue manager and receive messages. /// </summary> void ReceiveMessages() { XMSFactoryFactory factoryFactory; IConnectionFactory cf; IConnection connectionWMQ; ISession sessionWMQ; IDestination destination; IMessageConsumer consumer; ITextMessage textMessage; // Get an instance of factory. factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); // Create WMQ Connection Factory. cf = factoryFactory.CreateConnectionFactory(); Console.WriteLine("Connection Factory created."); // Set the properties cf.SetStringProperty(XMSC.WMQ_HOST_NAME, hostName); cf.SetIntProperty(XMSC.WMQ_PORT, port); cf.SetStringProperty(XMSC.WMQ_CHANNEL, channelName); cf.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT); cf.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, queueManagerName); if (sslKeyRepository != null) { cf.SetStringProperty(XMSC.WMQ_SSL_KEY_REPOSITORY, "sslKeyRepository"); } if (cipherSpec != null) { cf.SetStringProperty(XMSC.WMQ_SSL_CIPHER_SPEC, cipherSpec); } if (sslPeerName != null) { cf.SetStringProperty(XMSC.WMQ_SSL_PEER_NAME, sslPeerName); } if (keyResetCount != -1) { cf.SetIntProperty(XMSC.WMQ_SSL_KEY_RESETCOUNT, keyResetCount); } if (sslCertRevocationCheck != false) { cf.SetBooleanProperty(XMSC.WMQ_SSL_CERT_REVOCATION_CHECK, true); } cf.SetStringProperty(XMSC.USERID, "bagmon"); cf.SetStringProperty(XMSC.PASSWORD, "Iceair123"); // Create connection. connectionWMQ = cf.CreateConnection(); Console.WriteLine("Connection created."); // Create session sessionWMQ = connectionWMQ.CreateSession(false, AcknowledgeMode.AutoAcknowledge); Console.WriteLine("Session created."); // Create destination if (isTopic) { destination = sessionWMQ.CreateTopic(destinationName); } else { destination = sessionWMQ.CreateQueue(destinationName); } Console.WriteLine("Destination created."); // Create consumer consumer = sessionWMQ.CreateConsumer(destination); Console.WriteLine("Message Consumer created. Starting the connection now."); // Start the connection to receive messages. connectionWMQ.Start(); Console.WriteLine("Receive message: " + TIMEOUTTIME / 1000 + " seconds wait time"); // Wait for 30 seconds for messages. Exit if no message by then textMessage = (ITextMessage)consumer.Receive(TIMEOUTTIME); if (textMessage != null) { Console.WriteLine("Message received."); Console.Write(textMessage); Console.WriteLine("\n"); } else { Console.WriteLine("Wait timed out."); } // Cleanup consumer.Close(); destination.Dispose(); sessionWMQ.Dispose(); connectionWMQ.Close(); }
public static void Main(string[] args) { var env = MqEnvironment.Load("env.json"); if (args.Length == 0) { Console.WriteLine("Say which program you want to run; put, get, pub, sub, request, response"); Environment.Exit(0); } var xmsFactoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ); var connectionFactory = xmsFactoryFactory.CreateConnectionFactory(); connectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, env.Host); connectionFactory.SetIntProperty(XMSC.WMQ_PORT, env.Port); connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, env.Channel); connectionFactory.SetIntProperty(XMSC.WMQ_CONNECTION_MODE, XMSC.WMQ_CM_CLIENT); connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, env.Qmgr); if (env.KeyRepository != null && env.CipherSuite != null) { connectionFactory.SetStringProperty(XMSC.WMQ_SSL_KEY_REPOSITORY, env.KeyRepository); } if (env.CipherSuite != null) { connectionFactory.SetStringProperty(XMSC.WMQ_SSL_CIPHER_SPEC, env.CipherSuite); } //connectionFactory.SetStringProperty(XMSC.USERID, env.AppUser); //connectionFactory.SetStringProperty(XMSC.PASSWORD, env.AppPassword); try { switch (args[0]) { case "put": new SimpleProducer(connectionFactory, env).PutMessage(); break; case "get": new SimpleConsumer(connectionFactory, env, CancellationTokenSource.Token).GetMessages(); break; case "sub": new SimpleSubscriber(connectionFactory, env, CancellationTokenSource.Token).SubscribeMessages(); break; case "pub": new SimplePublisher(connectionFactory, env).PublishMessage(); break; case "request": connectionFactory.SetStringProperty(XMSC.WMQ_TEMPORARY_MODEL, env.ModelQueueName); new SimpleRequest(connectionFactory, env, CancellationTokenSource.Token).SendRequest(); break; case "response": new SimpleResponse(connectionFactory, env, CancellationTokenSource.Token).ReceiveMessages(); break; default: Console.WriteLine("Say which program you want to run; put, get, pub, sub, request, response"); break; } } catch (XMSException ex) { Console.WriteLine(ex); } }