I am trying to receive the message from the queue using ANSI-C and MQGET function. The problem is that I always get error 2010 (MQRC_DATA_LENGTH_ERROR).
I found out that this error concerns parameter 7 of the MQGET call (DataLength). The message on my queue has 7157460 bytes. The channel I am using for MQGET has the "Maximum message length" set to 104857600 (as well as the queue holding the message).
I am even using the MQGET from this example: http://www.capitalware.biz/dl/code/c/msg2file.zip
And I still end up with error 2010. What am I doing wrong? Should I somehow increase the maximum size of the message in MQSERVER environment variable?
MQGET call:
/* ... */
MQLONG messlen; /* message length received */
MQGET(Hcon, /* connection handle */
Hobj, /* object handle */
&md, /* message descriptor */
&gmo, /* get message options */
buflen, /* pBuffer length */
pBuffer, /* pointer to message buffer */
&messlen, /* message length */
&CompCode, /* completion code */
&Reason); /* reason code */
I've got it! The answer is to use MQCONNX call to connect to queue manager.
Example:
#include <cmqxc.h>
/* ... */
MQCNO mqcno = {MQCNO_DEFAULT} ; /* Connection options */
MQCD mqcd = {MQCD_CLIENT_CONN_DEFAULT}; /* Channel Defs */
/* ... */
mqcd.MaxMsgLength = 104857600L; /* 100 MB */
MQCONNX(mQueueManager.Name,
&mqcno,
&mQueueManager.ConnectionHandle,
&mQueueManager.CompletionCode,
&mQueueManager.ReasonCode);
It worked like a charm!
But please remember - if you find yourself needing to increase the maximum message size - think twice. There is probably something wrong with the design. In another words - MQ should not be used for transferring big messages. MQ File Transfer Edition is one of the solutions then.