jmsibm-mqrfh2mq-visual-edit

Why RFH2 header is put before the message instead of in the header?


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)

Solution

  • 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