|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
get RFH2 folders with php mqseries |
« View previous topic :: View next topic » |
Author |
Message
|
vasilev |
Posted: Mon Sep 30, 2024 12:32 am Post subject: get RFH2 folders with php mqseries |
|
|
 Acolyte
Joined: 31 Oct 2014 Posts: 71 Location: Germany
|
Hello,
I am reading the message with:
Code: |
$gmo = array('Options' => MQSERIES_MQGMO_PROPERTIES_FORCE_MQRFH2 | MQSERIES_MQGMO_FAIL_IF_QUIESCING | MQSERIES_MQGMO_NO_WAIT| MQSERIES_MQGMO_ACCEPT_TRUNCATED_MSG);
|
similar to Java.
in Mqseries.c i see:
Code: |
else if (!strncmp(msg_desc.Format, MQFMT_RF_HEADER_2, sizeof(msg_desc.Format))) {
MQRFH2 rfh2 = {MQRFH2_DEFAULT};
memcpy(&rfh2, buf, MQRFH_STRUC_LENGTH_FIXED_2);
data = buf + rfh2.StrucLength;
buf_len -= rfh2.StrucLength;
} |
and I receive the message data like:
JVBEkj34kskdjds+Zjkj23kjkj23...... so some encoded string.
Do you know how I can read it and decode it? or how i can read the rfh2.FolderStrings ?
thank you _________________ Regards
V.Vasilev |
|
Back to top |
|
 |
hughson |
Posted: Mon Sep 30, 2024 1:31 am Post subject: |
|
|
 Padawan
Joined: 09 May 2013 Posts: 1959 Location: Bay of Plenty, New Zealand
|
Can you show us your code (rather than the code in mqseries.c from the PHP library)?
Cheers,
Morag _________________ Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software |
|
Back to top |
|
 |
vasilev |
Posted: Mon Sep 30, 2024 1:49 am Post subject: |
|
|
 Acolyte
Joined: 31 Oct 2014 Posts: 71 Location: Germany
|
hello Morag,
sure. please find below.
Need to read the JMS folders.
for the test I have tried:
Code: |
data = buf + rfh2.FolderStrings;
mqseries.c:692:34: error: 'MQRFH2' {aka 'struct tagMQRFH2'} has no member named 'FolderStrings'
2.185 692 | data = buf + rfh2.FolderStrings;
|
but this is a function i guess and dont have the source for it - getFolderStrings i mean.
Code: |
$i=1;
while (true) {
$MQMD = array();
$gmo = array('Options' => MQGMO_PROPERTIES_FORCE_MQRFH2 | MQSERIES_MQGMO_FAIL_IF_QUIESCING | MQSERIES_MQGMO_NO_WAIT| MQSERIES_MQGMO_ACCEPT_TRUNCATED_MSG);
mqseries_get(
$conn["conn"],
$obj,
$MQMD,
$gmo,
1048576,
$msg,
$data_length,
$comp_code,
$reason);
if ($comp_code == MQSERIES_MQCC_OK) {
$msgId = mqseries_bytes_val($MQMD['MsgId']);
$CorrelId = mqseries_bytes_val($MQMD['CorrelId']);
$msgdata=$MQMD;
$msgdata["number"]=$i;
$msgdata["MsgId"]=bin2hex($msgId);
$msgdata["CorrelId"]=bin2hex($CorrelId);
$msgdata["length"]=$data_length." bytes";
$msgdata["userId"]=$msgdata["UserIdentifier"];
$msgdata["format"]=$msgdata["Format"];
$msgdata["CCSID"]=$msgdata["CodedCharSetId"];
$msgdata["PutDate"]=date("Y-m-d",strtotime($msgdata["PutDate"]));
$msgdata["PutTime"]=date("H:i:s",strtotime(substr($msgdata["PutTime"],0,6)));
$msgdata = array_map(function($v){
return is_string($v)?trim($v):$v;
}, $msgdata);
$msgdata["message"]=$msg;
unset($msgdata["UserIdentifier"],$msgdata["CodedCharSetId"],$msgdata["Format"],$msgdata["AccountingToken"]);
$allmsg[]=$msgdata;
if($type=="clear"){
$MQMD = array();
$gmo = array('Options' => MQSERIES_MQGMO_MSG_UNDER_CURSOR | MQSERIES_MQGMO_NO_WAIT | MQSERIES_MQGMO_FAIL_IF_QUIESCING | MQSERIES_MQGMO_ACCEPT_TRUNCATED_MSG);
mqseries_get(
$conn["conn"],
$obj,
$MQMD,
$gmo,
0,
$msg,
$data_length,
$comp_code,
$reason);
}
} else {
break;
}
$i++;
} |
[/code] _________________ Regards
V.Vasilev |
|
Back to top |
|
 |
RogerLacroix |
Posted: Tue Oct 01, 2024 12:07 pm Post subject: |
|
|
 Jedi Knight
Joined: 15 May 2001 Posts: 3264 Location: London, ON Canada
|
vasilev wrote: |
Code: |
data = buf + rfh2.FolderStrings;
mqseries.c:692:34: error: 'MQRFH2' {aka 'struct tagMQRFH2'} has no member named 'FolderStrings'
2.185 692 | data = buf + rfh2.FolderStrings; |
|
Did you look in the PHP/MQ documentation for what fields are supported?
If you look in the cmqc.h header file or the IBM MQ MQRFH2 documentation, you will see:
Code: |
typedef struct tagMQRFH2 MQRFH2;
typedef MQRFH2 MQPOINTER PMQRFH2;
struct tagMQRFH2 {
MQCHAR4 StrucId; /* Structure identifier */
MQLONG Version; /* Structure version number */
MQLONG StrucLength; /* Total length of MQRFH2 including all */
/* NameValueLength and NameValueData */
/* fields */
MQLONG Encoding; /* Numeric encoding of data that follows */
/* last NameValueData field */
MQLONG CodedCharSetId; /* Character set identifier of data that */
/* follows last NameValueData field */
MQCHAR8 Format; /* Format name of data that follows last */
/* NameValueData field */
MQLONG Flags; /* Flags */
MQLONG NameValueCCSID; /* Character set identifier of */
/* NameValueData */
}; |
All of the folders follow the NameValueCCSID field in the MQRFH2 structure. You have to write a parser that will parse the folders. It is not straightforward because each folder has a prefix length of the folder and padding of the folder to align on a 4-byte boundary.
i.e.
Code: |
{length of folder}{folder data}{padding of 0-3 bytes} |
vasilev wrote: |
Code: |
mqseries_get(
$conn["conn"],
$obj,
$MQMD,
$gmo,
0,
$msg,
$data_length,
$comp_code,
$reason);
|
|
Why is the BufferLength field 0 (zero)? You don't want the queue manager to return any message data? Just the MQMD structure?
later
Roger _________________ Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter |
|
Back to top |
|
 |
gbaddeley |
Posted: Tue Oct 01, 2024 4:27 pm Post subject: |
|
|
 Jedi Knight
Joined: 25 Mar 2003 Posts: 2538 Location: Melbourne, Australia
|
Roger is correct about parsing RFH structures and folders to obtain the property name/value pairs. MQLONG is a 32 bit integer. Byte order depends on encoding. MQCHAR are space filled, without null terminator. The parsing code is not difficult (been there, done that), but you need to fully understand the format. _________________ Glenn |
|
Back to top |
|
 |
vasilev |
Posted: Tue Oct 01, 2024 9:35 pm Post subject: |
|
|
 Acolyte
Joined: 31 Oct 2014 Posts: 71 Location: Germany
|
thank you .
the 0 is for the deleting of the message.
I am not so good in C , there is no information and also the NameValueCCSID is not in the mqseries code.
if i am not wrong, i have to add it in : https://github.com/php/pecl-networking-mqseries/blob/master/mqseries_helper.c like this:
here it should be defined for RFH not for MQMD .. not sure how.
Code: |
#ifdef MQMD_VERSION_1
case MQMD_VERSION_1:
......
MQSERIES_ADD_ASSOC_LONG(msg_desc, Encoding);
MQSERIES_ADD_ASSOC_LONG(msg_desc, CodedCharSetId);
MQSERIES_ADD_ASSOC_LONG(msg_desc, NameValueCCSID); |
and in: https://github.com/php/pecl-networking-mqseries/blob/master/mqseries.c
but not 100% sure :
Code: |
else if (!strncmp(msg_desc.Format, MQFMT_RF_HEADER_2, sizeof(msg_desc.Format))) {
MQRFH2 rfh2 = {MQRFH2_DEFAULT};
memcpy(&rfh2, buf, MQRFH_STRUC_LENGTH_FIXED_2);
data = buf + rfh2.NameValueCCSID;
buf_len -= rfh2.StrucLength;
} |
tried and messagedata is empty.
or if there is some sample in C please provide it to see if I can put it here.. but again not sure.
After some tests also with amqsbcg (even without specifying 3 for PropOption RFH.. ) i saw that the php is not giving the rfh header in the message. the message is a pdf so it is normal to be not readable format, but i dont see the rfh header before the message..
Can this be changed with the php mqseries and how
thank you _________________ Regards
V.Vasilev |
|
Back to top |
|
 |
hughson |
Posted: Wed Oct 02, 2024 1:01 am Post subject: |
|
|
 Padawan
Joined: 09 May 2013 Posts: 1959 Location: Bay of Plenty, New Zealand
|
vasilev wrote: |
After some tests also with amqsbcg (even without specifying 3 for PropOption RFH.. ) i saw that the php is not giving the rfh header in the message. the message is a pdf so it is normal to be not readable format, but i dont see the rfh header before the message.. |
So what does the format field of the MQMD say if this message does not have an MQRFH2 on the front.
Did the putter of the message put an RFH2 on the front? Was it from JMS - is that why you are expecting an RFH2 on the front? Have you perhaps set PROPCTL on the queue definition to a value that would strip the RFH2, e.g. PROPCTL(NONE).
Try getting the message using the IBM supplied sample amqsiqm. It will show properties if there are any.
vasilev wrote: |
Can this be changed with the php mqseries and how |
If there was no RFH2 at put time, you can't create one on the get.
In fact, why don't you start by creating a simple message using amqsstm with a property on it, and get your code working with that so that you know that it can handle properties, and then throw this message that may or may not have properties on it at your code.
You said at the beginning of this thread:-
vasilev wrote: |
I receive the message data like:
JVBEkj34kskdjds+Zjkj23kjkj23...... so some encoded string. |
and now you have told us that the message is a PDF. So I guess that explains that? A bit of googling shows that Base64-encoded PDF files will always start with JVBE. That is somewhat outside of the scope of a forum about IBM MQ though.
Cheers,
Morag _________________ Morag Hughson @MoragHughson
IBM MQ Technical Education Specialist
Get your IBM MQ training here!
MQGem Software |
|
Back to top |
|
 |
vasilev |
Posted: Wed Oct 02, 2024 2:00 am Post subject: |
|
|
 Acolyte
Joined: 31 Oct 2014 Posts: 71 Location: Germany
|
yes, this explains that
no all is fine with the message, the problem is how the rfh is taken from the C ..
with some help from Copilot i was able to read it and see the folders in the beginning:
in mqseries_helper:
Code: |
void extract_rfh2_header(MQBYTE *msg, MQRFH2 *rfh2Header) {
memcpy(rfh2Header, msg, sizeof(MQRFH2));
} |
in mqseries:
Code: |
MQRFH2 rfh2Header;
extract_rfh2_header(buf, &rfh2Header);
array_init(return_value);
add_assoc_stringl(return_value, "data", data, data_length);
add_assoc_stringl(return_value, "rfh2Header", (char *)&rfh2Header, sizeof(MQRFH2)); |
this is providing:
Code: |
Array
(
[data] => RFH ☻X"☻3♥MQSTR �♦0<usr><color>red</color><test>value</test></usr>
[rfh2Header] => RFH ☻X"☻3♥MQSTR �♦
)
|
the other is just php substr and extract the xml.
this was good idea with amqsstm, thanks ! _________________ Regards
V.Vasilev |
|
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
|
|
|
|