Im trying to put a message with some headers to a topic and get them using a java client. However, I am able to successfully put the message with headers, but unable to get the headers from the message. Here is the code I'm trying.
Put to Topic
MQMessage message = new MQMessage();
MQDLH mqdlh = new MQDLH();
mqdlh.setDestQName("DEV.QUEUE.1");
mqdlh.setIntValue("Reason", 10);
MQTM mqtm = new MQTM();
mqtm.setApplId("TestAppId");
mqtm.setProcessName("TestProcessName");
MQHeaderList headerList = new MQHeaderList();
headerList.add(mqdlh);
headerList.add(mqtm);
headerList.write(message);
MQPropertyDescriptor d = new MQPropertyDescriptor();
d.version = MQPD_USER_CONTEXT;
message.writeString("Your message payload");
topic.put(message);
Get from Topic
MQMessage msg = new MQMessage();
MQGetMessageOptions gmo = new MQGetMessageOptions();
gmo.options = MQGMO_WAIT;
gmo.waitInterval = MQConstants.MQWI_UNLIMITED;
topic.get(msg, gmo);
MQHeaderIterator iterator = new MQHeaderIterator(msg);
while (iterator.hasNext()) {
MQHeader header = iterator.nextHeader();
System.out.println(header);
}
The iterator always returns an empty result here. However, if I try to read headers one by one as follows, I'm able to successfully get them.
MQDLH dlh = new MQDLH();
dlh.read(msg);
System.out.println(new String(dlh.getDestQName()));
System.out.println((dlh.getValue("Reason")));
I'm unable to understand the issue here and any help regarding this is much appreciated. Is there any configuration that I should give to make this work?
------------------------------
Dilan Nayanajith
------------------------------