|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
MQ Message Problem |
« View previous topic :: View next topic » |
Author |
Message
|
nan |
Posted: Mon Aug 04, 2008 4:30 am Post subject: MQ Message Problem |
|
|
Newbie
Joined: 30 Jul 2008 Posts: 3
|
Hi,
The below code gets the information from queue and prints it on the screen. But when I try to print the value of buffer, I dont get the entire value of it. I just get the first character of the data. That is, if buffer has, "Qname.Filname.AAA", the output of this program is just "Q". Kindly help me in solving this issue. Also, let me know where I have gone wrong.
#include <stdio.h>
#include <stdlib.h>
#include <cmqc.h>
#define NO_COMMITS 'N'
#define YES_COMMITS 'Y'
#define CONN_CONNECTED 'C'
#define CONN_DISCONNECTED 'D'
#define QUEUE_OPEN 'O'
#define QUEUE_CLOSED 'C'
#define FILE_REC_LEN 1024
/* Declare MQI structures needed */
MQOD od = {MQOD_DEFAULT}; /* Object Descriptor */
MQMD md = {MQMD_DEFAULT}; /* Message Descriptor */
MQGMO gmo = {MQGMO_DEFAULT}; /* GET message options */
MQHCONN Hcon; /* connection handle */
MQHOBJ Hobj; /* object handle */
MQLONG O_options; /* MQOPEN options */
MQLONG C_options; /* MQCLOSE options */
MQLONG CompCode; /* completion code */
MQLONG OpenCode; /* MQOPEN completion code */
MQLONG Reason; /* reason code */
MQLONG CReason; /* reason code for MQCONN */
MQLONG buflen; /* buffer length */
MQLONG messlen; /* message length */
unsigned char buffer[20000]; /* message buffer */
FILE *fp;
char command[100];
char filename[100];
char CommitSw = NO_COMMITS;
char PassLQMgr[200];
char PassTriggerQueue[100];
char ConnStatus = CONN_DISCONNECTED;
char QueueStatus = QUEUE_CLOSED;
void main()
{
strcpy(PassLQMgr,"LQMGR");
strcpy(PassTriggerQueue, "QL.TRIGGER.QUEUE");
/*strcpy(PassTriggerQueue, "QL.APP.ONLINE");*/
/******************************************************************/
/* Connect to queue manager */
/******************************************************************/
if (ConnStatus == CONN_DISCONNECTED)
{
printf("Connect to MQ Queue Manager %s\n", PassLQMgr);
MQCONN(PassLQMgr, /* queue manager */
&Hcon, /* connection handle */
&CompCode, /* completion code */
&CReason); /* reason code */
}
printf("reason code %ld\n", CReason);
printf("completion code %ld\n", CompCode);
if (CompCode == MQCC_FAILED)
{
printf("FATAL ERROR: ");
printf("MQCONN FAILED - connect with Queue Manager - reason code %ld\n", CReason);
}
else
printf("Connection Success\n");
strncpy(od.ObjectQMgrName, PassLQMgr, (size_t)MQ_Q_NAME_LENGTH);
strncpy(od.ObjectName, PassTriggerQueue, (size_t)MQ_Q_NAME_LENGTH);
if (QueueStatus == QUEUE_CLOSED)
{
O_options = MQOO_INPUT_AS_Q_DEF /* open queue for input */
+ MQOO_FAIL_IF_QUIESCING; /* but not if MQM stopping */
MQOPEN(Hcon, /* connection handle */
&od, /* object descriptor for queue */
O_options, /* open options */
&Hobj, /* object handle */
&OpenCode, /* MQOPEN completion code */
&Reason); /* reason code */
printf("MQ open reason code %ld\n", Reason);
printf("MQ Open code %ld\n", OpenCode);
/* report reason, if any; stop if failed */
if (Reason != MQRC_NONE)
{
printf("FATAL ERROR: ");
printf("MQOPEN FAILED - WMS Trigger Queue - reason code %ld\n", Reason);
}
if (OpenCode == MQCC_FAILED)
{
printf("FATAL ERROR: ");
printf("Unable to open queue for input\n");
}
/* End program if error was encountered */
if((Reason != MQRC_NONE) ||
(OpenCode == MQCC_FAILED))
if (Reason == MQRC_NONE &&
OpenCode != MQCC_FAILED)
QueueStatus = QUEUE_OPEN;
}
/****************************************************************/
/* GET a message from the WMS "trigger" queue. */
/****************************************************************/
memcpy(md.MsgId, MQMI_NONE, sizeof(md.MsgId));
memcpy(md.CorrelId, MQCI_NONE, sizeof(md.CorrelId));
buflen = sizeof(buffer) - 1;
gmo.Options = MQGMO_WAIT
+ MQGMO_CONVERT;
+ MQGMO_SYNCPOINT;
gmo.WaitInterval = 03000;
MQGET(Hcon,
Hobj,
&md,
&gmo,
buflen,
buffer,
&messlen,
&CompCode,
&Reason);
printf("MQ GET reason code %ld\n", Reason);
printf("MQ GET completion code %ld\n", CompCode);
printf("msg id and corr id are %ld %ld\n", *md.MsgId,*md.CorrelId);
printf("Buffer is %s\n", buffer);
printf("bufflen %d\n", buflen);
printf("messlen %d\n", messlen);
}
Thanks,
nan |
|
Back to top |
|
 |
gbaddeley |
Posted: Tue Aug 05, 2008 6:56 pm Post subject: |
|
|
 Jedi Knight
Joined: 25 Mar 2003 Posts: 2538 Location: Melbourne, Australia
|
Quote: |
gmo.Options = MQGMO_WAIT
+ MQGMO_CONVERT;
+ MQGMO_SYNCPOINT; |
Invalid syntax. Delete the first semi-colon.
Quote: |
printf("msg id and corr id are %ld %ld\n", *md.MsgId,*md.CorrelId); |
msg id and corr id are 24 byte binary fields. You can't treat them as pointers to integers! The only sensible way to display them is using a function which will dump the bytes in hex.
Quote: |
printf("Buffer is %s\n", buffer); |
C strings need a null terminator, so add code:
buffer[messlen] = '\0';
before you printf buffer. _________________ Glenn |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|