I create a small application to subscribe message from definite topic. In my test environment I have only trial version WebSphere MQ and i don't know how can I put message to the my definite topic. I can put message to queue and get it, but when i want get message from definite topic, a get a empty message.
Update
Moved question update from another answer by OP into the question.
I use sample code C:\Program Files\IBM\WebSphere MQ\Tools\dotnet\samples\cs\base\SimpleSubscribe
// mq properties
properties = new Hashtable();
properties.Add(MQC.HOST_NAME_PROPERTY, hostName);
properties.Add(MQC.PORT_PROPERTY, port);
properties.Add(MQC.CHANNEL_PROPERTY, channelName);
#region pass
properties.Add(MQC.USER_ID_PROPERTY, "LOGIN");
properties.Add(MQC.PASSWORD_PROPERTY, "PASSWORD");
#endregion
properties.Add(MQC.MQCA_TOPIC_NAME, "News.Topic");
if (sslKeyRepository != null)
{
properties.Add(MQC.SSL_CERT_STORE_PROPERTY, sslKeyRepository);
}
if (cipherSpec != null)
{
properties.Add(MQC.SSL_CIPHER_SPEC_PROPERTY, cipherSpec);
}
if (sslPeerName != null)
{
properties.Add(MQC.SSL_PEER_NAME_PROPERTY, sslPeerName);
}
if (keyResetCount != 0)
{
properties.Add(MQC.SSL_RESET_COUNT_PROPERTY, keyResetCount);
}
if (sslCertRevocationCheck != false)
{
MQEnvironment.SSLCertRevocationCheck = sslCertRevocationCheck;
}
if (transportMode == "managed")
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_MANAGED);
else if (transportMode == "unmanaged")
properties.Add(MQC.TRANSPORT_PROPERTY, MQC.TRANSPORT_MQSERIES_CLIENT);
// create connection
Console.Write("Connecting to queue manager.. ");
queueManager = new MQQueueManager(queueManagerName, properties);
Console.WriteLine("done");
// accessing topic
Console.Write("Accessing topic " + topicName + ".. ");
if (durability == "nondurable")
topic = queueManager.AccessTopic(topicName, null, MQC.MQTOPIC_OPEN_AS_SUBSCRIPTION, MQC.MQSO_CREATE | MQC.MQSO_FAIL_IF_QUIESCING);
else if (durability == "durable")
topic = queueManager.AccessTopic(topicName, null, MQC.MQSO_CREATE | MQC.MQSO_FAIL_IF_QUIESCING | MQC.MQSO_DURABLE | MQC.MQSO_RESUME, null, "DurableSubscriptionName");
Console.WriteLine("done");
// creating a message object
message = new MQMessage();
message.WriteString(messageString);
int time = 1;
// getting messages continuously
for (int i = 1; i <= numberOfMsgs; i++)
{
// creating a message object
message = new MQMessage();
try
{
topic.Get(message);
Console.WriteLine("Message " + i + " got = " + message.ReadString(message.MessageLength));
message.ClearMessage();
}
catch (MQException mqe)
{
if (mqe.ReasonCode == 2033)
{
++time;
--i;
Console.WriteLine("No message available");
Thread.Sleep(1000);
//waiting for 10sec
if (time > 10)
{
Console.WriteLine("Timeout : No message available");
break;
}
continue;
}
else
{
Console.WriteLine("MQException caught: {0} - {1}", mqe.ReasonCode, mqe.Message);
}
}
}
// closing topic
Console.Write("Closing topic.. ");
topic.Close();
Console.WriteLine("done");
// disconnecting queue manager
Console.Write("Disconnecting queue manager.. ");
queueManager.Disconnect();
Console.WriteLine("done");