0

I need to create a message with RFH2 header and inject it in IBM MQ. Please find below how the message is created.

def message = new MQMessage()
def rfh2 = new MQRFH2()
rfh2.setEncoding(CMQC.MQENC_NATIVE)
rfh2.setCodedCharSetId(CMQC.MQCCSI_INHERIT)
rfh2.setFormat("        ")
rfh2.setNameValueCCSID(1208)
rfh2.setFieldValue('mcd', 'Msd', 'jms_byte')
rfh2.setFieldValue('jms', 'Dst', 'queue:///myqueue')
rfh2.setFieldValue('jms', 'Pri', 0)
rfh2.setFieldValue('usr', 'Sender', 'mysender')
rfh2.write(message)

message.writeString('''${msgText}''')

However, it seems that header content is not put in the header but before the message. Please find below an example:

Server logs with message sent with MQ Visual Edit

Header

 2020-04-21 11:07:59.913 DEBUG 48093 --- [DefaultMessageListenerContainer-2] 
 c.b.i.c.listeners.AbstractAgiListener    : Receive message on MQ with header : {someargs, 
 jms_destination=queue:///myqueue, someargs, Sender=mysender, someargs, jms_type=mcd://jms_byte,
 someargs}

Message

 <Document ...>...</Document>

Server logs with message sent with above code

Header

 2020-04-21 11:07:59.913 DEBUG 48093 --- [DefaultMessageListenerContainer-2] 
 c.b.i.c.listeners.AbstractAgiListener    : Receive message on MQ with header : {someargs}

Message

 RFH ¨ÿÿÿþ        ¸ <mcd><Msd>jms_bytes</Msd></mcd> 8<jms><Dst>queue:///myqueue</Dst>
<Pri>0</Pri></jms>    <usr><Sender>mysender</Sender></usr><Document ...>...</Document>

Any idea how to solve it please? Thank you.

Update 1

Even with the below code, information are still present before the message

def message = new MQMessage()
def rfh2 = new MQRFH2()
rfh2.setEncoding(CMQC.MQENC_NATIVE)
rfh2.setCodedCharSetId(CMQC.MQCCSI_INHERIT)
rfh2.setFormat(CMQC.MQFMT_NONE)
rfh2.setNameValueCCSID(1208)
rfh2.setFieldValue('mcd', 'Msd', 'jms_byte')
rfh2.setFieldValue('usr', 'Sender', 'mysender')
rfh2.write(message)
Roger
  • 7,062
  • 13
  • 20
Royce
  • 1,557
  • 5
  • 19
  • 44
  • Does this answer your question? [How to send message with RFH2 format?](https://stackoverflow.com/questions/61321214/how-to-send-message-with-rfh2-format) – JoshMc Apr 21 '20 at 10:00
  • This answer explain how to do with JMeter thank you. But not how to solve my header issue. – Royce Apr 21 '20 at 10:01
  • So change `rfh2.setFormat(" ")` to `rfh2.setFormat("RHF2")`? Because the guy in charge of the application told me "You need to put 8 blanks in Format field". – Royce Apr 21 '20 at 10:06
  • Actually that is automatic when you call `rfh2.write`. You should set you format like this which should be the same as blanks `rfh2.setFormat(CMQC.MQFMT_NONE)`. Also only call `rfh2.setFieldValue` for the `usr` property, the other three are set when you call `rfh2.write`. – JoshMc Apr 21 '20 at 10:32
  • @JoshMc thank you. I updated my question with new code based on your comment. – Royce Apr 21 '20 at 12:38
  • No mcd either. Rfh is part of message body, jms api will handle it. – JoshMc Apr 21 '20 at 14:28
  • Ok but if I remove `mcd`, the server is not able to read the message... Do you think that it is the reason why information are not put in the header? Moreover, you said that `Rfh is part of message body` so it is not possible to put this information in the header? Like `MQ Visual Edit` do? – Royce Apr 21 '20 at 14:40

1 Answers1

2

rfh2.setFormat("RHF2")

That is not valid.

rfh2.setFormat(CMQC.MQFMT_NONE)

That says the message payload has no type. i.e. It is not string or another internal is not found after this RFH2 structure.

Like MQ Visual Edit do?

Yes, MQ Visual Edit uses the MQRFH2 class but you need to understand that it is up to the programmer to code the correct MQMD.Format value.

Did you set the message's MQMD.Format to MQFMT_RF_HEADER_2:

msg.format = CMQC.MQFMT_RF_HEADER_2;

I have posted a lot of fully functioning Java (non-JMS) programs that create a MQRFH2 (aka JMS) message both here on StackOverflow and on my blog.

You can search MQRFH2 with my name to find them here.

Here's one that describes how MQ Visual Edit handles displaying named properties vs raw MQRFH2 message. https://www.capitalware.com/rl_blog/?p=4786

Here is one that shows how to create a JMS (MQRFH2) message in non-JMS Java application: https://www.capitalware.com/rl_blog/?p=4823

And finally, one that shows to handle an incoming JMS (MQRFH2) Message in non-JMS Java application: https://www.capitalware.com/rl_blog/?p=4811

Roger
  • 7,062
  • 13
  • 20
  • Thank you a lot, very interesting blog! `msg.format = CMQC.MQFMT_RF_HEADER_2` fixed my issue! I just have one last question. In my process, a message is send in another queue when the injected message has been treated. Can you explain me how to find this message? Indeed, I need to extract content of this message before to continue the process. Thank you in advance. – Royce Apr 22 '20 at 08:45
  • I tried but I'm facing an issue when I try to retrieve the message. Could you please help me on it? https://stackoverflow.com/questions/61365813/mqexception-mqje001-completion-code-2-reason-2033-while-trying-to-retreiv Many thanks – Royce Apr 22 '20 at 13:16