using System.Collections;
private String hostName = "localhost";
private String channelName = "SYSTEM.DEF.SVRCONN";
private String queueManagerName = null;
private String queueName = null;
private const String messageString = "test message";
private int numberOfMsgs = 1;
private String sslKeyRepository = null;
private String cipherSpec = null;
private String sslPeerName = null;
private int keyResetCount = 0;
private Boolean sslCertRevocationCheck = false;
private MQQueueManager queueManager;
private Hashtable properties;
private MQMessage message;
static void Main(String[] args)
Console.WriteLine("Start of SimplePut Application\n");
SimplePut simplePut = new SimplePut();
if (simplePut.ParseCommandline(args))
catch (ArgumentException ex)
Console.WriteLine("Invalid arguments!\n{0}", ex);
Console.WriteLine("Exception caught: {0}", ex);
Console.WriteLine("Sample execution FAILED!");
Console.WriteLine("\nEnd of SimplePut Application\n");
bool ParseCommandline(string[] args)
if (args.Length < 2 || args.Length % 2 == 1)
for (int argIndex = 0; argIndex < args.Length; argIndex++)
token = (String)args.GetValue(argIndex);
queueName = (String)args.GetValue(argIndex + 1);
hostName = (String)args.GetValue(argIndex + 1);
port = Convert.ToInt32((String)args.GetValue(argIndex + 1));
channelName = (String)args.GetValue(argIndex + 1);
numberOfMsgs = Convert.ToInt32((String)args.GetValue(argIndex + 1));
sslKeyRepository = (String)args.GetValue(argIndex + 1);
cipherSpec = (String)args.GetValue(argIndex + 1);
sslPeerName = (String)args.GetValue(argIndex + 1);
keyResetCount = Convert.ToInt32((String)args.GetValue(argIndex + 1));
sslCertRevocationCheck = Convert.ToBoolean((String)args.GetValue(argIndex + 1));
Console.WriteLine("Exception caught in parsing command line arguments: " + e.Message);
Console.WriteLine(e.StackTrace);
Console.WriteLine("Usage: SimplePut -q queueName -k keyRepository -s cipherSpec [-h host -p port -l channel -n numberOfMsgs -dn sslPeerName -kr keyResetCount -cr sslCertRevocationCheck]");
Console.WriteLine("- queueName : a queue name");
Console.WriteLine("- keyRepository : can be *SYSTEM or *USER");
Console.WriteLine("- cipherSpec : cipherSpec like TLS_RSA_WITH_AES_128_CBC_SHA");
Console.WriteLine("- host : hostname like 192.122.178.78. Default hostname is localhost");
Console.WriteLine("- port : port number like 3555. Default port is 1414");
Console.WriteLine("- channel : connection channel. Default is SYSTEM.DEF.SVRCONN");
Console.WriteLine("- numberOfMsgs : The number of messages. Default is 1");
Console.WriteLine("- sslPeerName : distinguished name of the server certificate");
Console.WriteLine("- keyResetCount : KeyResetCount value.");
Console.WriteLine("- sslCertRevocationCheck : can be true or false");
Console.WriteLine("Ex: SimplePut -q QA -k *SYSTEM -s TLS_RSA_WITH_AES_128_CBC_SHA");
Console.WriteLine(" SimplePut -q B -k *SYSTEM -s TLS_RSA_WITH_AES_128_CBC_SHA -h remotehost -p 1414 -l SYSTEM.DEF.SVRCONN -dn CN=IBMWEBSPHEREMQQM07 -kr 40000 -cr false");
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);
if (sslKeyRepository != null)
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);
if (sslCertRevocationCheck != false)
MQEnvironment.SSLCertRevocationCheck = sslCertRevocationCheck;
Console.WriteLine("MQ Parameters");
Console.WriteLine("1) queueName = " + queueName);
Console.WriteLine("2) keyRepository = " + sslKeyRepository);
Console.WriteLine("3) cipherSpec = " + cipherSpec);
Console.WriteLine("4) host = " + hostName);
Console.WriteLine("5) port = " + port);
Console.WriteLine("6) channel = " + channelName);
Console.WriteLine("7) numberOfMsgs = " + numberOfMsgs);
Console.WriteLine("8) sslPeerName = " + sslPeerName);
Console.WriteLine("9) keyResetCount = " + keyResetCount);
Console.WriteLine("10) sslCertRevocationCheck = " + sslCertRevocationCheck);
Console.Write("Connecting to queue manager.. ");
queueManager = new MQQueueManager(queueManagerName, properties);
Console.WriteLine("done");
Console.Write("Accessing queue " + queueName + ".. ");
queue = queueManager.AccessQueue(queueName, MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING);
Console.WriteLine("done");
message = new MQMessage();
message.WriteString(messageString);
for (int i = 1; i <= numberOfMsgs; i++)
Console.Write("Message " + i + " <" + messageString + ">.. ");
Console.WriteLine("put");
Console.Write("Closing queue.. ");
Console.WriteLine("done");
Console.Write("Disconnecting queue manager.. ");
queueManager.Disconnect();
Console.WriteLine("done");
Console.WriteLine("MQException caught: {0} - {1}", mqe.ReasonCode, mqe.Message);
Console.WriteLine(mqe.StackTrace);