how to retrieve RFH message headers from a message coming from MQ? - java

Can anyone please help me in retrieving message headers from the message coming from Websphere IBM MQ ?
We are using JMS OnMessage method to browse the MQ and the type of message received from MQ is "BytesMessage". We want to iterate through the RFH message headers and collect them.
We have tried using MQHeaders to iterate over the MQMessage but could not as it was throwing an exception.
Please advice me.

a good place to start reading is https://www.ibm.com/support/knowledgecenter/en/SSFKSJ_8.0.0/com.ibm.mq.dev.doc/q031990_.htm which explains how IBM MQ implements JMS.
Next you should print out your received JMS Message with toString() or iterate through your properties and check the properties you receive. Depending on RFH or RFH2 you will see different fields.
You can find explanations for these fields in https://www.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.dev.doc/q032000_.htm
and https://www.ibm.com/support/knowledgecenter/SSFKSJ_8.0.0/com.ibm.mq.dev.doc/q032060_.htm

Related

Set ReplyToQMgr and ReplyToQ in Apache Camel reout to receive COA using IBM MQ

I am using Apache Camel and IBM MQ to send messages. I need to receive COA when a message gets delivered to a remote queue. The general picture looks like this:
When the message reaches msg_q2 queue, I should receive the COA back. So, the problem is that I am not able to set the QMGR_REM as reply-to queue manager, which is supposed to produce COA.
https://www.ibm.com/docs/en/ibm-mq/8.0?topic=messages-reply-queue-queue-manager
I tried setting JMS_IBM_MQMD_xxx headers, but for some reason those headers either get omitted or ignored (by Camel?), and the message fails to be put on the queue with the reason that the reply-to queue is not specified. Also, I tried setting JMSReplyTo header as queue://reply-to-qmgr/reply-to-q. In this case the queue:// part gets removed, and the rest is simply set as a reply-to queue name.
I am relatively new to Apache Camel, and IBM MQ, so any input would be very appreciated. Thank you in advance!
In your application, just provide the name of your ReplyToQ as replyToQ1 and leave the ReplyToQMgr field blank. The queue manager will fill it in with the local queue manager name QMGR_LOC for you.
And on QMGR_REC do one of the following:-
If your transmission queue for the channel from QMGR_REM to QMGR_LOC is named exactly QMGR_LOC, you have nothing further to do. When QMGR_REM comes to put the COA onto queue replyToQ1 on queue manager QMGR_LOC, it will resolve it to the transmission queue that has the name QMGR_LOC and the channel will deliver it.
If your transmission queue for the channel from QMGR_REM to QMGR_LOC is not named exactly QMGR_LOC, then make the following definition on QMGR_REM:
DEFINE QREMOTE(QMGR_LOC) RNAME(' ') RQMNAME(QMGR_LOC) +
XMITQ(your-transmission-queue-going-to-QMGR_LOC)
So, basically by trial and error I figured out that adding mdWriteEnabled=true property onCamelJmsDestinationName Camel header made it working as I need.
The code is something like this:
route.setHeader("CamelJmsDestinationName", "queue:///msg_q1?targetClient=1&mdWriteEnabled=true")
Then I set reply-to queue manager via MQMD property
route.setHeader("JMS_IBM_MQMD_ReplyToQMgr", "QMGR_REM")
and reply-to queue
route.setHeader("JMSReplyTo", "replyToQ2")

Check message source in Jms - Weblogic 12c

In our application we have configured our jms queue in weblogic and sending messages as ByteMessage after converting the object to byte array.
We are reading messages from the queue in asynchronous manner using onMessge method.
As we are sending the messages as byte message so in receiving end we are parsing the Message object to ByteMessage. But here for some of the messages we are getting ClassCastException.
We are not able to find out from where these messages are coming and how to stop them. We are also setting Jms type to identify that these messages are sent by us, but for these messages jms type is coming as null.
Anyone has any idea how to fix it?
Exception:
weblogic.jms.common.ObjectMessageImpl can not be cast to javax.jms.ByteMessage

Camel route - get JMSMessageId after sent

How can I get JMSMessageID in camel route producer (with Spring context),
JMSMessageID needs to be generated by MQ server, like it works with native JMS.
In the camel's documentation
JMSMessageID is in section "consumer",
"Camel adds the following JMS properties to the In message headers when it receives a JMS message",
but I need it from producer side after send.
I can's use tmpReply queue with camel's InOut.
I suppose, I need to use MessagePostProcessor, or MessageSentCallback, but I don't know how.
Thanks a lot!
This works for me:
from("someRoute")
.to("jms://OUTPUT.QUEUE?includeSentJMSMessageID")
.log("JMSMessageID = ${header.JMSMessageID}");

Steps for publishing message to Solace

I have heard about Solace and I'm reading about it but I don't know much yet about it. I have a HashMap:
{Swaps_snaptime=2016-04-26T07:00:00.000Z, Swaps_20Y=2036-04-29 0.004588, Swaps_15Y=2031-04-29}
And I want to publish this to Solace. How do I do that? What are the steps I need to follow? Please help!
You need to execute the following tasks to send a message:
Connect to the Solace Message Router
Create a producer
Create the message object
Send the message
There's a simple example of how to do the above at the Solace website.
Note that the example makes use of TextMessages.
In order to send your map, you can do the following:
Serialize your map, and then send it as part of a BytesMessage.
Place the contents of your map into a MapMessage.
Place the contents of your map into a StreamMessage
Use any message type, and place the contents of your map into the header portion of the message. Refer to How to send the header along with payload in Solace.

How do I identify reply vs. response in a jms topic?

Suppose both reply and request are being sent to the same topic, and now I'm subscribed to it. How do I identify which of them is which?
Try setting message property on the messages which you publish to the topic. You set a string property on each message, e.g. message_type=”request” or message_type=”response”. When you consume the message on the listener you can read the property to identify if the message is request or response.
Another way of doing it is by starting two listeners with message selector properties. One which will only consume messages with message_type property as “request” and another which will only consume messages with message_type property as “response”.
There is an easy way too: The request comes in first, so I can check for a smaller timestep than the response. Which will identify it as the request.

Categories