assimbly / gateway

A message gateway based on Apache Camel
Apache License 2.0
69 stars 9 forks source link

Question: how to set the correct data type (hex/byte?) for a JMS_IBM_MQMD header #691

Closed petervdz closed 1 year ago

petervdz commented 2 years ago

We need to set the JMSMessageID for IBM MQ in the messages for a specific flow. To do this, we fill the JMS_IBM_MQMD_MsgId (see xml below) in a route - but when sending the message to IBM MQ it returns an error: JMSCC0051: The property 'JMS_IBM_MQMD_MsgId' should be set using type '[B', not 'java.lang.String'. How to do it properly?

Example code:

assimbly commented 2 years ago

@petervdz

  1. It's uncommon to set the JMS MessageID manually:

https://stackoverflow.com/questions/23299147/how-to-set-jmsmessageid-and-jmscorrelationid-properly

So normally this ID is set by Camel/Assimbly. There are a few options to work with MessageID (https://camel.apache.org/components/3.14.x/jms-component.html). The IBMMQ component is based on the Camel JMS Component.

  1. Setting the type of an header:

Generally, you can set the result type of a header like this:

  <setHeader headerName="myKey">
    <simple resultType="java.lang.String">myValue</simple>
   </setHeader>

   As a byte array:

  <setHeader headerName="myKey">
    <simple resultType="byte[]">myValue</simple>
   </setHeader>

   or from a header

  <setHeader headerName="myKey">
    <simple resultType="byte[]">${header.someKey}</simple>
   </setHeader> 

3) Also note that it sometimes tricky to connect to IBMMQ (it's more extensive than most MQ's). I once need to set a HEX literally (because it needed a HEX in EBCDIC)

assimbly commented 2 years ago

p.s. I could discuss this with @tomosjut when needed (because I now don't have a IBMMQ instance to test).

petervdz commented 2 years ago

Hi Raymond, I know it's uncommon to want to set the JMSMessageID, but in this case it's neccesary (temporary) because our integration platform is put in between an existing chain to be able to fase out some old legacy. I will try the code-suggestions! And @tomosjut is now on a holiday but will be back soon! Regards, Peter.

petervdz commented 2 years ago

I've tried the setHeader as suggested, it now doesn't give me the error above any more (so thanks!), but still IBM MQ generates its own msgid - so setting the JMS_IBM_MQMD_MsgId - which I found in some posts shoud do the trick - doesn't work here.

tomosjut commented 2 years ago

It is indeed uncommon to set the JMSMessageID yourself. It even goes against JMS specifications. But it is possible to set your own JMSMessageID. There are a few things to take in account:

skin27 commented 1 year ago

Closing as Thomas port this to Fuse.