views:

397

answers:

3

I'm not extremely familiar with IBM MQSeries, but I am writing c# scripts which write and read files from my queue server. The problem is my read works but my write doesn't. Please notice that I am using the same queue so don't bother going in that direction.

My code firstly accesses the MQserver with the following code:

MQQueueManager qManager;
MQQueue queue;
MQMessage queueMessage;
MQGetMessageOptions queueGetMessageOptions;
MQPutMessageOptions queuePutMessageOptions;

string QueueName;

public MQAccess(string queueName, string queueManager, string connection, string channel)
{
    QueueName = queueName;

    qManager = new MQQueueManager(queueManager, channel, connection);

    queue = qManager.AccessQueue(QueueName, MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING);
}

I am able to read files from my queue with this code:

public bool NextMessage(ref string message, ref DateTime putDateTime)
{
    queueMessage = new MQMessage();
    queueMessage.Format = MQC.MQFMT_STRING;
    queueGetMessageOptions = new MQGetMessageOptions();

    queueGetMessageOptions.Options = MQC.MQOO_INPUT_AS_Q_DEF + MQC.MQOO_FAIL_IF_QUIESCING;

    try
    {
        queue.Get(queueMessage, queueGetMessageOptions);
    }
    catch (MQException mqex)
    {
        if (mqex.ReasonCode == MQC.MQRC_NO_MSG_AVAILABLE)
        {
            message = "";
            return false;
        }
        else
            throw mqex;
    }
    message = queueMessage.ReadString(queueMessage.MessageLength);
    putDateTime = queueMessage.PutDateTime;

    if (message.StartsWith("´╗┐"))
    {
        message = message.Substring(3, message.Length - 3);
    }

    return true;
}

If I however try to write with the following code it gives me errors:

public void WriteMessage(string message)
{
    queueMessage = new MQMessage();
    queueMessage.WriteString(message);
    queueMessage.Format = MQC.MQFMT_STRING;
    queuePutMessageOptions = new MQPutMessageOptions();

    queue.Put(queueMessage, queuePutMessageOptions);
}

My error catch gives me the error:

Error in the application

Which doesn't show much of course. So I checked the event log on the server and this showed me the error:

An error occurred receiving data from stx041774 (192.168.225.51) over TCP/IP. This may be due to a communications failure.

The return code from the TCP/IP (recv) call was 10054 (X'2746'). Record these values and tell the systems administrator.

I looked up 10054 and means:

An existing connection was forcibly closed by the remote host.

Does anyone have any idea what I can do to make this work? Is there perhaps an MQC option I have to set for writing? Because I have no idea what to do with the options, I'm not even sure if this is the issue.

Please keep in mind that I also close my connection every time with:

public void Close()
{
    queueMessage = null;
    queue.Close();
    qManager.Close();
}

~MQAccess()
{
    queueMessage = null;
    queue.Close();
    qManager.Close();
}
A: 

Maybe having a look at this article on CodeProject, in relation to MSMQ protocol, the article implements a chat system.

Hope this helps, Best regards, Tom.

tommieb75
This is MSMQ, I'm talking about IBM MQSeries
WtFudgE
@wtfudge: Oh sorry...bummer! maybe it might have been better to edit your question to emphasize IBM MQSeries, not MSMQ...as not to confuse with the two...
tommieb75
whatever floats your boat -edited-
WtFudgE
+1  A: 

Just as you set your get options when getting messages you also need to set put options when you put a message

queuePutMessageOptions = MQC.MQOO_OUTPUT + MQC.MQOO_FAIL_IF_QUIESCING

is what your missing.

squig
The put message options are MQPMO_, the open options are MQOO_ and you are mixing the two.
T.Rob
+1  A: 

Squig was close but no cigar. When you open the queue, you need to specify both input and output on the open options if you want to both read and write messages. The example code has only input options specified.

T.Rob