Author |
Message
|
Mohd-Imran |
Posted: Mon Apr 02, 2007 12:37 am Post subject: MQ - MQHRF2 with Visual basic |
|
|
Novice
Joined: 01 Apr 2007 Posts: 12
|
Hi,
First time i am using MQ , I build application in Visual Basic 6.0 to connect mq and put message and get message. Issue is that I need to put message with MQRFH2 (message header) but i am unable to do this , Acutally i don't know how to do this , if anybody help me in this regard and if possible send me code so i add this code in my application.
Need this very very urgent. |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 02, 2007 12:57 am Post subject: Re: MQ - MQHRF2 with Visual basic |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Mohd-Imran wrote: |
Issue is that I need to put message with MQRFH2 (message header) but i am unable to do this , |
MQRFH2 is one of the headers supplied in the .bas file you've already got included with your VB app if it's successfully connecting and putting messages. So all you need to do is add the header to the payload buffer, change whatever parts of the RFH2 you need to set (type and so forth according to your needs), and change the MQMD.Format to the RFH2 constant. IIRC one of the samples deals with this, but it's been a while & I don't have VB6 installed atm to look.
The Application Programming Reference describes the RFH2 in detail, and expands a bit on how it's used. Do beware of code snippets either from the board or the samples; the variable length section of the RFH2 makes simply pasting code a bit dicey..... Use them for what they are; reference and start points. It's not tricky code, just a bit fiddly.
(Especially as no two users of the RFH2 will have the same requirement!) _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Mohd-Imran |
Posted: Mon Apr 02, 2007 1:22 am Post subject: |
|
|
Novice
Joined: 01 Apr 2007 Posts: 12
|
Thanks for reply , but i am unable to understand, below is few lines of my code , its great if you guide me little more:
buffer = my xml , body of message
buflen = lenght of my message
Dim md As MQMD ' Message descriptor
Dim pmo As MQPMO ' MQPUT message options
MQMD_DEFAULTS md
md.Format = MQFMT_STRING
MQPMO_DEFAULTS pmo
MQPUT gHcon, gHobj, md, pmo, buflen, Buffer, CompCode, Reason[/i] |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 02, 2007 1:34 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Ok, so you'd have
buffer = rfh2 set according to your needs + your xml ' including the RFH2 format being string
buflen = length of buffer as above
...
md.Format = MQFMT_RF_HEADER_2
... _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Mohd-Imran |
Posted: Mon Apr 02, 2007 1:39 am Post subject: |
|
|
Novice
Joined: 01 Apr 2007 Posts: 12
|
Thanks again, and sorry if i bother you again. but still not getting you.
can you please define , if possible with examples
buffer = rfh2 set according to your needs + your xml ' including the RFH2 format being string
buflen = length of buffer as above
md.Format = MQFMT_RF_HEADER_2
Regards, |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 02, 2007 1:46 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Mohd-Imran wrote: |
Thanks again, and sorry if i bother you again. but still not getting you.
can you please define , if possible with examples
buffer = rfh2 set according to your needs + your xml ' including the RFH2 format being string
buflen = length of buffer as above
md.Format = MQFMT_RF_HEADER_2
Regards, |
I think md.Format = MQFMT_RF_HEADER_2 is about as clear as it's going to get!
Aside from that, you need to set up the RFH2 according to whatever you need it to be (I'm assuming because you're trying to add it to the message you have some requirement to use it, probably to set type), include it with your message, ensure the buffer length is set correctly to the combined message length and set the format as I indicate.
If you don't understand any of this, especially that Format statement which is actually syntatically correct VB then I commend the Application Reference manual to you, which describes in detail why this is necessary and what it does.
I struggle to see how I can be any clearer, but if you do have specific questions (aside from the "how do I do this then" which I feel I've answered) do not be shy of posting them. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Mohd-Imran |
Posted: Mon Apr 02, 2007 3:34 am Post subject: |
|
|
Novice
Joined: 01 Apr 2007 Posts: 12
|
Code: |
I think md.Format = MQFMT_RF_HEADER_2 is about as clear as it's going to get!
Aside from that, you need to set up the RFH2 according to whatever you need it to be (I'm assuming because you're trying to add it to the message you have some requirement to use it, probably to set type), include it with your message, ensure the buffer length is set correctly to the combined message length and set the format as I indicate.
If you don't understand any of this, especially that Format statement which is actually syntatically correct VB then I commend the Application Reference manual to you, which describes in detail why this is necessary and what it does.
I struggle to see how I can be any clearer, but if you do have specific questions (aside from the "how do I do this then" which I feel I've answered) do not be shy of posting them. |
Dear i cant get you , my question is that i put the message in queue as i mention , but how i put message header (mqrfht2 )with put message. can you please describe in detail in help of code , cause on internet i found lots of article but not sample for MQRFH2.
Thanks |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 02, 2007 3:42 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Mohd-Imran wrote: |
how i put message header (mqrfht2 )with put message. |
Vitor wrote: |
buffer = rfh2 set according to your needs + your xml ' including the RFH2 format being string
buflen = length of buffer as above |
 _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Mohd-Imran |
Posted: Mon Apr 02, 2007 3:45 am Post subject: |
|
|
Novice
Joined: 01 Apr 2007 Posts: 12
|
With your extensive help i am able to place a message in mq with MQRFH2 format , but there is another requirement from interface team that they want this below XML to be placed as an HEADER in our message.
how we can achieve this.
<usr><VersionId>2</VersionId><FunctionId>IMRAN-FUNC</FunctionId><UserId>Dell</UserId></usr>
Interface team has provided me sample of dotnet application. but how to achieve this in VB i can't understand
objMsg = new MQMessageClass();
objMsg.Format = FORMAT_MESSAGE_HRF2;
objMsg.Persistence = (int)MQ.MQPER_PERSISTENT;
objMsg.WriteString (rfh2.StrucId);
objMsg.WriteInt4 (rfh2.Version);
objMsg.WriteInt4 (rfh2.StrucLength + mcd_len + jms_len + usr_len + 12);
objMsg.WriteInt4 (rfh2.Encoding);
objMsg.WriteInt4 (rfh2.CodedCharSetId);
objMsg.WriteString (rfh2.Format);
objMsg.WriteInt4 (rfh2.Flags);
objMsg.WriteInt4 (rfh2.NameValueCCSID);
objMsg.WriteInt4 (mcd_len);
objMsg.WriteString (mcd_data);
objMsg.WriteInt4 (jms_len);
objMsg.WriteString (jms_data);
objMsg.WriteInt4 (usr_len);
objMsg.WriteString (usr_data);
objMsg.WriteString (this.Data); |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 02, 2007 3:50 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
This is EXACTLY why I said to be wary of sample code. I have also already said:
Vitor wrote: |
The Application Programming Reference describes the RFH2 in detail, and expands a bit on how it's used. Do beware of code snippets either from the board or the samples; the variable length section of the RFH2 makes simply pasting code a bit dicey |
So as I suspected they're carrying data in the variable length section. Described, as I said, in detail in the documentation and not a very hard programming job if you follow the rules given in the manual. Even a quick glance at the .NET sample supplied shows the structure of the thing; converting that into a series of VB statetments is a straightforward programming task!
They've even covered the important issue of the length for you. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Mohd-Imran |
Posted: Mon Apr 02, 2007 4:00 am Post subject: |
|
|
Novice
Joined: 01 Apr 2007 Posts: 12
|
Dear thanks for your continous answer now i am atleast able to change message format , but still unable to add my require fields in mqrfh2 , I didn't understand where i put below xml :
<usr><VersionId>2</VersionId><FunctionId>MYDIASACCINQ</FunctionId><UserId>GIBKMY2</UserId></usr>
after puting this the queue data is like : (this is sample )
52 46 48 20 02 00 00 00 RFH ....
88 00 00 00 22 02 00 00 ...."...
B5 01 00 00 20 20 20 20 ...
20 20 20 20 00 00 00 00 ....
B8 04 00 00 60 00 00 00 ...`...
3C 75 73 72 3E 3C 46 75 <usr><Fu
6E 63 74 69 6F 6E 49 64 nctionId
3E 4D 59 44 49 41 53 41 >MYDIASA
43 43 49 4E 51 3C 2F 46 CCINQ</F
75 6E 63 74 69 6F 6E 49 unctionI
64 3E 3C 56 65 72 73 69 d><Versi
6F 6E 49 64 3E 32 3C 2F onId>2</
56 65 72 73 69 6F 6E 49 VersionI
64 3E 3C 55 73 65 72 49 d><UserI
64 3E 54 48 4F 47 4B 57 d>THOGKW
43 3C 2F 55 73 65 72 49 C</UserI
64 3E 3C 2F 75 73 72 3E d></usr>
3C 3F 78 6D 6C 20 76 65 <?xml ve
72 73 69 6F 6E 3D 22 31 rsion="1
2E 30 22 20 65 6E 63 6F .0" enco |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 02, 2007 4:22 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
At first glance it looks right. Not checked all the length fields (it's Monday & I can't be asked to think in hex ) but you've got static RFH2 / variable section / XML document. And the variable section contains all your data, with the tags properly closed.
What's the problem? _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Mohd-Imran |
Posted: Mon Apr 02, 2007 4:26 am Post subject: |
|
|
Novice
Joined: 01 Apr 2007 Posts: 12
|
The sample which i paste its not generated from my form , this is sample provieded by Interaction Team and they wants same from visual basic application.
I am very thankful if you send some vb source code ......... |
|
Back to top |
|
 |
Vitor |
Posted: Mon Apr 02, 2007 4:31 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
The .NET example they've given you is a good template that will translate into VB without too much issue.
If all else fails you can reverse engineer the example message in about 5 minutes and the Application Reference.
(If the problem here is you don't have the reference, you'll find the link to the online infocentre in about 1 post in 5 here. 1 post in 3 if you search for jefflowrey's posts!)
If you want me to write source code, do a proper statement of requirements and I'll quote you costs. Advice is free (and you've had quite a lot this morning), coding I make a living doing.
As do you I suspect.  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
Mohd-Imran |
Posted: Mon Apr 02, 2007 6:37 pm Post subject: |
|
|
Novice
Joined: 01 Apr 2007 Posts: 12
|
Thanks , But i don't want you to code for me, I know Coding , i Just want to give me proper solution, In net I also found that its easy do this and this but no body put any single example for vb. For .net and java and c there is lots of examples free of cost available. Below is my code and i just want to know where i need to change and MQRFH2 header is attached with my message body.
Global Const MQFMT_STRING = "MQRFH2"
*********'
'* MQRFH2 Structure -- Rules and Formatting Header 2 *'
'*************************************************************
Type MQRFH2
StrucId As String * 4 'Structure identifier'
Version As Long 'Structure version number'
struclength As Long 'Total length of MQRFH2 including all NameValueLength and NameValueData fields'
Encoding As Long 'Numeric encoding of data that follows NameValueData'
CodedCharSetId As Long 'Character set identifier of data that follows NameValueData'
Format As String * 8 'Format name of data that follows NameValueData'
Flags As Long 'Flags'
NameValueCCSID As Long 'Character set identifier of NameValueData'
NameValueData As String
End Type
Global MQRFH2_DEFAULT As MQRFH2
*********
'**********************************************************************'
'* MQRFH2_DEFAULTS Subroutine -- Initialise MQRFH2 to default values *'
'**********************************************************************'
Sub MQRFH2_DEFAULTS(Struc As MQRFH2)
Struc.StrucId = MQRFH_STRUC_ID
Struc.Version = MQRFH_VERSION_2
Struc.struclength = MQRFH_STRUC_LENGTH_FIXED_2
Struc.Encoding = MQENC_NATIVE
Struc.CodedCharSetId = MQCCSI_INHERIT
Struc.Format = MQFMT_NONE
Struc.Flags = MQRFH_NONE
Struc.NameValueCCSID = 1208
End Sub
******************
In Form
///////////////////////
MQMD_DEFAULTS md
md.Format = MQFMT_STRING
Dim xmloption As String
xmloption = "<?xml version = '1.0' encoding='UTF-8'?>" 'Messagebody
buflen = Len(xmloption)
Buffer = xmloption
'---------
MQPUT gHcon, gHobj, md, pmo, buflen, Buffer, CompCode, Reason
MsgBox "Sucessfully Put message"
///////////////////////////
Please advise. |
|
Back to top |
|
 |
|