Tips for writing a simple IBM® MQ managed .NET SSL application, including examples for setting the SSL properties for connection factories, creating a queue manager instance, connection, session and destination, and sending a test message.
Before you begin
You must first configure SSL for managed IBM MQ.NET as described
in Configuring SSL for managed IBM MQ .NET.
For application program
configuration in base .NET, set SSL properties either using the MQEnvironment
class or by supplying a hashtable as part of the MQQueueManager constructor.
For
application program configuration in XMS .NET, you set the SSL properties
on the property context of the connection factories.
Procedure
-
Set the SSL properties for the connection factories as shown in the following examples.
- Example for IBM MQ.NET
-
properties = new Hashtable();
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
properties.Add(MQC.HOST_NAME_PROPERTY, hostName);
properties.Add(MQC.PORT_PROPERTY, port);
properties.Add(MQC.CHANNEL_PROPERTY, channelName);
properties.Add(MQC.SSL_CERT_STORE_PROPERTY, sslKeyRepository);
properties.Add(MQC.SSL_CIPHER_SPEC_PROPERTY, cipherSpec);
properties.Add(MQC.SSL_PEER_NAME_PROPERTY, sslPeerName);
properties.Add(MQC.SSL_RESET_COUNT_PROPERTY, keyResetCount);
properties.Add("CertificateLabel", "ibmwebspheremq");
MQEnvironment.SSLCertRevocationCheck = sslCertRevocationCheck;
- Example for XMS .NET
-
cf.SetStringProperty(XMSC.WMQ_SSL_KEY_REPOSITORY, "sslKeyRepository");
cf.SetStringProperty(XMSC.WMQ_SSL_CIPHER_SPEC, cipherSpec);
cf.SetStringProperty(XMSC.WMQ_SSL_PEER_NAME, sslPeerName);
cf.SetIntProperty(XMSC.WMQ_SSL_KEY_RESETCOUNT, keyResetCount);
cf.SetBooleanProperty(XMSC.WMQ_SSL_CERT_REVOCATION_CHECK, true);
-
Create the queue manager instance, connections, session and destination as shown in the following examples.
- Example for MQ .NET
-
queueManager = new MQQueueManager(queueManagerName, properties);
Console.WriteLine("done");
// accessing queue
Console.Write("Accessing queue " + queueName + ".. ");
queue = queueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
Console.WriteLine("done");
- Example for XMS .NET
-
connectionWMQ = cf.CreateConnection();
// Create session
sessionWMQ = connectionWMQ.CreateSession(false, AcknowledgeMode.AutoAcknowledge);
// Create destination
destination = sessionWMQ.CreateQueue(destinationName);
// Create producer
producer = sessionWMQ.CreateProducer(destination);
-
Send a message as shown in the following examples.
- Example for MQ .NET
-
// creating a message object
message = new MQMessage();
message.WriteString(messageString);
// putting messages continuously
for (int i = 1; i <= numberOfMsgs; i++)
{
Console.Write("Message " + i + " <" + messageString + ">.. ");
queue.Put(message);
Console.WriteLine("put");
}
- Example for XMS .NET
-
textMessage = sessionWMQ.CreateTextMessage();
textMessage.Text = simpleMessage;
producer.Send(textMessage);
-
Verify the SSL connection.
Check the channel status to verify that the SSL connection has been established and is working correctly.