I'm trying to implement MQ publish/subscribe in a C#/.Net application.
I've following the instructions in this tutorial:
https://tekslate.com/publish-subscribe-in-websphere-mq-series/
- a) Queue manager: QM
- b) TCP Listener running, port: 1420
- c) Topic name: NEWS.SPORTS.CRICKET
- d) Subscription name also: NEWS.SPORTS.CRICKET
- e) Topic string: NEW/SPORTS/CRICKET
- f) Destination queue: SportsQ
I'm successfully able to to a "test publish" in MQ Explorer. I see "message count = 1" in the subscription. I see "queue depth = 1" in SportsQ
I'm able to connect to QM, I'm able to access the topic ... but it just hangs when I do a "topic.Get(message")
Q: Why is MQ "Get()" hanging?????
Code:
using IBM.WMQ;
using System;
using System.Collections;
namespace HelloSubscribe
{
class Program
{
static void Main(string[] args)
{
string qmName = "QM";
string hostName = "localhost";
string strPort = "1420";
string channelName = "SYSTEM.DEF.SVRCONN";
string transport = MQC.TRANSPORT_MQSERIES_CLIENT;
Hashtable connectionProperties = new Hashtable();
connectionProperties.Add(MQC.HOST_NAME_PROPERTY, hostName);
connectionProperties.Add(MQC.PORT_PROPERTY, strPort);
connectionProperties.Add(MQC.CHANNEL_PROPERTY, channelName);
MQQueueManager mqQueueManager = new MQQueueManager(qmName, connectionProperties);
string topicObject = null;
string topicString = "NEWS/SPORTS/CRICKET";
string subscriptionName = "NEWS.SPORTS.CRICKET";
string topicName = "NEWS.SPORTS.CRICKET";
int openOptionsForGet = MQC.MQSO_CREATE | MQC.MQSO_FAIL_IF_QUIESCING | MQC.MQSO_DURABLE | MQC.MQSO_RESUME;
MQTopic destForGet = mqQueueManager.AccessTopic(topicString, null, openOptionsForGet, null, subscriptionName);
MQMessage messageForGet = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.Options |= MQC.MQGMO_WAIT | MQC.MQGMO_FAIL_IF_QUIESCING;
gmo.WaitInterval = 1000; // wait 60 seconds
destForGet.Get(messageForGet, gmo);
string msg = messageForGet.ReadLine();
destForGet.Close();
mqQueueManager.Disconnect();
mqQueueManager.Close();
}
}
}
I'm running WebSphere MQ 7.5, using the installed version of amqdnet.dll, and Visual Studio 2015.