|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Setting message properties |
« View previous topic :: View next topic » |
Author |
Message
|
Boomn4x4 |
Posted: Fri Oct 05, 2012 8:48 am Post subject: Setting message properties |
|
|
Disciple
Joined: 28 Nov 2011 Posts: 172
|
I had a simple C function that put messages on a queue. Message descriptor values were set via parameters passed to the function. Now, we want to attach a checksum to the message, from what I was reading, I should do this via message properties. Using the set message properties sample program as a guide line, I added this to my function. My program compiles, but the message properties are not appended to the message.
My assumption is that I've got some kind of conflict with message properties and the existing message descriptor.
Below is the code for reference. Any help would be appreciated
Code: |
MiStatus msg_send(const char *destType,
const char *destination,
const char *message,
uint32_t messageLength,
uint32_t persistence,
uint32_t priority,
const char *checksum)
{
MiStatus rv = MIS_OK;
stringstream logMsg;
char QMgrName[MQ_Q_MGR_NAME_LENGTH];
MQOD od = {MQOD_DEFAULT}; // Object Descriptor
MQMD md = {MQMD_DEFAULT}; // Message Descriptor
MQPMO pmo = {MQPMO_DEFAULT}; // put message options
MQCMHO cmho = {MQCMHO_DEFAULT}; // create message handle options
MQDMHO dmho = {MQDMHO_DEFAULT}; /* delete message handle options */
MQSMPO smpo = {MQSMPO_DEFAULT}; // set message property options
MQPD pd = {MQPD_DEFAULT}; // property descriptor
MQCHARV vs = {MQCHARV_DEFAULT}; // variable length string for message property
MQHMSG Hmsg; // message handle
MQLONG CreateCode = MQCC_FAILED; // MQCRTMH completion code
MQHCONN Hcon; // connection handle
MQLONG valuelen = 40; // length of sha1hash
MQLONG CompCode; // completion code
MQLONG Reason; // reason code
MQLONG CReason; // reason code for MQCONN
MQCNO ConnectOpts = {MQCNO_DEFAULT};
MQCD channelDef = {MQCD_CLIENT_CONN_DEFAULT};
char name[1024]; // property name
char value[valuelen];
strcpy(value, checksum);
logMsg << "Hash Value: " << value;
LogMessage(MSG_INFO, logMsg);
// check for queue or topic semantics
if (MIS_OK != xlateDestType(destType, destination, &od)) {
logMsg << "Invalid queue or topic semantics, expected 'QUEUE' or 'TOPIC'. Received: " << destType;
LogMessage(MSG_ERR, logMsg);
return MIS_INVALID_ARGS;
}
//init_MQCD(&channelDef);
ConnectOpts.ClientConnPtr = &channelDef;
ConnectOpts.ClientConnOffset = 0;
//validate persistence
if(validatePersistence(persistence))
{
logMsg << "Invalid Message Persistence: " << persistence;
LogMessage(MSG_ERR, logMsg);
return MIS_INVALID_ARGS;
}
md.Persistence = persistence;
QMgrName[0] = '\0'; //Ensure we are sending to default QMgr
MQCONNX(QMgrName, &ConnectOpts, &Hcon, &CompCode, &CReason);
if (MQCC_FAILED == CompCode)
{
//writeXML((char *)message);
logMsg << __FILE__ << ": " << __LINE__ << "MQCONNX failed CompCode=" << CompCode << " ReasonCode=" << CReason;
LogMessage(MSG_ERR, logMsg);
// xmon_alert("4w", "red", "MQ_MSGS", "MQCONNX Failed!");
return MIS_CONNECTION_FAILED;
}
//Create Message Handle
cmho.Options = MQCMHO_VALIDATE; /* validate property name */
MQCRTMH(Hcon, /* connection handle */
&cmho, /* create message handle options */
&Hmsg, /* message handle */
&CreateCode, /* MQCRTMH completion code */
&Reason); /* reason code */
//Set message properties
vs.VSPtr = name;
vs.VSOffset = 0;
vs.VSBufSize = 0;
vs.VSLength = valuelen;
vs.VSCCSID = MQCCSI_APPL;
strcpy(name,"sha1"); //set property name
logMsg << "Name " << name;
LogMessage(MSG_INFO, logMsg);
MQSETMP(Hcon, /* connection handle */
Hmsg, /* message handle */
&smpo, /* set message property options */
&vs, /* property name */
&pd, /* property descriptor */
MQTYPE_STRING, /* property data type */
valuelen, /* value length */
value, /* value buffer */
&CompCode, /* completion code */
&Reason); /* reason code */
strncpy(od.ObjectName, destination, strlen(destination)); //Set the queue name
md.Encoding = CCSID_UTF8;
memcpy(md.Format, MQFMT_STRING, (size_t) MQ_FORMAT_LENGTH);
md.Persistence = persistence; // Set message persistence
md.Priority = priority; // Set message priority
pmo.Options = MQPMO_NO_SYNCPOINT // Set Put Message Options
| MQPMO_FAIL_IF_QUIESCING
| MQPMO_NEW_MSG_ID
| MQPMO_NEW_CORREL_ID;
pmo.Version = MQPMO_VERSION_3; /* message handles were added */
/* to version 3 of the pmo */
pmo.OriginalMsgHandle = Hmsg; /* set the message properties */
//Fire message to MQ, and forget it.
MQPUT1(Hcon, &od, &md, &pmo, messageLength, (char *)message, &CompCode, &Reason);
if (MQRC_NONE != Reason)
{
rv = MIS_SEND_FAILED;
//writeXML((char *)message);
logMsg << __FILE__ << ":" << __LINE__ << " MQPUT1 failed. ReasonCode: " << Reason;
LogMessage(MSG_ERR, logMsg);
// xmon_alert("4w", "red", "MQ_MSGS", "MQ Message Send Failed");
}
else
{
logMsg << "MQPUT Successful. Message: " << message;
LogMessage(MSG_INFO, logMsg);
rv = MIS_OK;
// xmon_alert("4w", "green", "MQ_MSGS", "POS is sucessfully posting messages to MQ");
}
//Delete message handler to free up memory
MQDLTMH(Hcon, /* connection handle */
&Hmsg, /* object handle */
&dmho, /* delete message handle options */
&CompCode, /* completion code */
&Reason); /* reason code */
MQDISC(&Hcon, &CompCode, &Reason);
if (MQRC_NONE != Reason)
{
logMsg << __FILE__ << ":" << __LINE__ << " MQDISC failed. ReasonCode: " << Reason;
LogMessage(MSG_WARN, logMsg);
}
return rv;
} |
|
|
Back to top |
|
 |
mqjeff |
Posted: Fri Oct 05, 2012 9:00 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
How have you verified that the message property is not set on the message? |
|
Back to top |
|
 |
Boomn4x4 |
Posted: Fri Oct 05, 2012 9:04 am Post subject: |
|
|
Disciple
Joined: 28 Nov 2011 Posts: 172
|
mqjeff wrote: |
How have you verified that the message property is not set on the message? |
When I run the sample program, I go into the MQ Explorer and browse messages. There is an object for "Named Properties" in the message. "Name Properties" is not there for the messages from the program I posted above. |
|
Back to top |
|
 |
bruce2359 |
Posted: Fri Oct 05, 2012 9:40 am Post subject: |
|
|
 Poobah
Joined: 05 Jan 2008 Posts: 9469 Location: US: west coast, almost. Otherwise, enroute.
|
I don't see logic in your app to test ReasonCodes following MQCRTMH and MQSETMP, and before the MQPUT1. Are you certain the message properties calls were successful? _________________ I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live. |
|
Back to top |
|
 |
Boomn4x4 |
Posted: Fri Oct 05, 2012 10:33 am Post subject: |
|
|
Disciple
Joined: 28 Nov 2011 Posts: 172
|
bruce2359 wrote: |
I don't see logic in your app to test ReasonCodes following MQCRTMH and MQSETMP, and before the MQPUT1. Are you certain the message properties calls were successful? |
I put some tests in and my MQSETMP is returning a 2442, which is 2442 (098A) (RC2442): MQRC_PROPERTY_NAME_ERROR
So I guess that would narrow it down to the problem being in this block:
Code: |
vs.VSPtr = name;
vs.VSOffset = 0;
vs.VSBufSize = 0;
vs.VSLength = valuelen;
vs.VSCCSID = MQCCSI_APPL;
strcpy(name,"sha1"); //set property name
logMsg << "Name " << name;
LogMessage(MSG_INFO, logMsg);
MQSETMP(Hcon, /* connection handle */
Hmsg, /* message handle */
&smpo, /* set message property options */
&vs, /* property name */
&pd, /* property descriptor */
MQTYPE_STRING, /* property data type */
valuelen, /* value length */
value, /* value buffer */
&CompCode, /* completion code */
&Reason); /* reason code */ |
However, I'm logging the name, and it is displaying correctly and I don't see how any of those characters "sha1" are invalid. |
|
Back to top |
|
 |
bruce2359 |
Posted: Fri Oct 05, 2012 10:47 am Post subject: |
|
|
 Poobah
Joined: 05 Jan 2008 Posts: 9469 Location: US: west coast, almost. Otherwise, enroute.
|
Quote: |
vs.VSPtr = name;
vs.VSOffset = 0;
vs.VSBufSize = 0;
vs.VSLength = valuelen;
vs.VSCCSID = MQCCSI_APPL; |
vs.VSLength = strlen(vs.VSPtr) _________________ I like deadlines. I like to wave as they pass by.
ב''ה
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live. |
|
Back to top |
|
 |
Boomn4x4 |
Posted: Fri Oct 05, 2012 11:20 am Post subject: |
|
|
Disciple
Joined: 28 Nov 2011 Posts: 172
|
bruce2359 wrote: |
vs.VSLength = strlen(vs.VSPtr) |
Thank you... It was vs.VSLength = strlen(name)... but that helped.
This is the data I am now getting in the message:
Code: |
00000 52 46 48 20 02 00 00 00--6C 00 00 00 B8 04 00 00 |RFH ....l...¸...|
00010 B8 04 00 00 4D 51 53 54--52 20 20 20 00 00 00 00 |¸...MQSTR ....|
00020 B8 04 00 00 44 00 00 00--3C 75 73 72 3E 3C 73 68 |¸...D...<usr><sh|
00030 61 31 00 04 3E 31 32 33--34 35 36 37 38 39 00 FB |a1..>123456789.û|
00040 BF 6D 72 C2 B5 54 EC FB--BF 18 00 00 00 38 D9 FB |¿mrµTìû¿....8Ùû|
00050 BF DE F4 30 08 34 68 95--08 6F 41 99 08 3C 2F 73 |¿Þô0.4h..oA..</s|
00060 68 61 31 00 04 3E 3C 2F--75 73 72 3E 54 45 53 54 |ha1..></usr>TEST| |
I passed the sha1 property the value 123456789.. and it looked like it correctly stuck it in the usr tags. However, this brings up a new question. When I ran the sample program, the results were much cleaner. I think it has something to do with the format. The sample program outputs in format MQSTR where as the program I have is (now after theses changes) is MQRFH2. Likewise instead of having "Named Properties" I have "MQRFH2 Properties" |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Oct 05, 2012 11:26 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Does the sample program use MQPUT1?
Does the sample program exhibit the difference in behavior to the *same* queue? |
|
Back to top |
|
 |
Boomn4x4 |
Posted: Fri Oct 05, 2012 11:31 am Post subject: |
|
|
Disciple
Joined: 28 Nov 2011 Posts: 172
|
mqjeff wrote: |
Does the sample program use MQPUT1?
Does the sample program exhibit the difference in behavior to the *same* queue? |
No, the sample program does not use a PUT1
Yes, it does exhibit the difference in behavior in the same queue. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Oct 05, 2012 11:34 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Boomn4x4 wrote: |
mqjeff wrote: |
Does the sample program use MQPUT1?
Does the sample program exhibit the difference in behavior to the *same* queue? |
No, the sample program does not use a PUT1
Yes, it does exhibit the difference in behavior in the same queue. |
Does the sample program use *any* MQOPEN options that are *not* strictly default? |
|
Back to top |
|
 |
Boomn4x4 |
Posted: Mon Oct 08, 2012 5:40 am Post subject: |
|
|
Disciple
Joined: 28 Nov 2011 Posts: 172
|
mqjeff wrote: |
Does the sample program use *any* MQOPEN options that are *not* strictly default? |
Thanks for nudging me in the right direction  |
|
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
|
|
|
|