• 1 reply
  • Latest Post - ‏2012-12-04T18:31:39Z by SystemAdmin
8523 Posts

Pinned topic Problem reconnecting using XMS and a message selector in consumer

‏2012-11-27T19:50:19Z |
I wrote a very simple command-line application in C# (.NET Framework 3.5) using the XMS library (version to send and receive messages to a WMQ queue (version 7.1). I installed the WMQ client for Windows (version in my laptop, which I'm also using to write the application.

The following is basically my program:

// Create a connection factory
XMSFactoryFactory factoryFactory = XMSFactoryFactory.GetInstance(XMSC.CT_WMQ);
connectionFactory = factoryFactory.CreateConnectionFactory();

// Set the properties
connectionFactory.SetStringProperty(XMSC.WMQ_HOST_NAME, Settings.Default.Host);
connectionFactory.SetIntProperty(XMSC.WMQ_PORT, Settings.Default.Port);
connectionFactory.SetStringProperty(XMSC.WMQ_CHANNEL, Settings.Default.Channel);
connectionFactory.SetStringProperty(XMSC.WMQ_QUEUE_MANAGER, Settings.Default.QueueManager ?? "");

// In case of network issues - reconnect to same queue manager
connectionFactory.SetStringProperty(XMSC.WMQ_CONNECTION_NAME_LIST, String.Format("{0}({1})", Settings.Default.Host, Settings.Default.Port));
connectionFactory.SetIntProperty(XMSC.WMQ_CLIENT_RECONNECT_TIMEOUT, Settings.Default.ReconnectPeriod);;

// Create connection.
connection = connectionFactory.CreateConnection(Settings.Default.Username, Settings.Default.Password);

// Create session
session = connection.CreateSession(false, AcknowledgeMode.AutoAcknowledge);

// Create destination
destination = session.CreateQueue(Settings.Default.Destination);

// Start the connection and receive messages from destination

// Create the message consumer now
messageConsumer = session.CreateConsumer(destination, "storeno='" + store + "'", );
for (int i = 0; i < 3; i++)
var message = messageConsumer.Receive();
// --- Print the content of the message ---

If I run this program without disconnecting the network cable from my laptop, everything runs fine (that is, if I put three message in my queue, my program prints the contents of those three messages). If I disconnect the network cable between the second and third call to Receive(), the program is not able to get the third message.
However, if I remove the message selector (param) from the call to CreateConsumer(), the program behaves as expected (that is, it can receive and print the content of the third message, even if I disconnect my laptop).

Am I doing something wrong or is this a legit bug in the XMS library?
Updated on 2012-12-04T18:31:39Z at 2012-12-04T18:31:39Z by SystemAdmin
  • SystemAdmin
    8523 Posts

    Re: Problem reconnecting using XMS and a message selector in consumer

    Turns out that the reconnection issue was probably due to the actual message (either how it was written by WESB or the specific headers/properties). The snippet of code posted previously works fine with a simple text message (if you put one in a queue using MQ Explorer).
    Also, we upgraded the MQ server and client to version 7.5 and again, the previous code works fine.
    So, to recap, having a message selector had nothing to do with the problem while reconnecting.
    However, even with MQ version 7.5, there was another problem: After running the client and waiting for the first message, if there's a network disconnection, after the client reconnects, it's no longer able to receive messages.
    The solution to this time was to use a transacted session.