|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
StringProperty not correctly set when using MQ with JMS |
« View previous topic :: View next topic » |
Author |
Message
|
gebrian |
Posted: Mon Jun 30, 2008 11:34 pm Post subject: StringProperty not correctly set when using MQ with JMS |
|
|
Newbie
Joined: 30 Jun 2008 Posts: 3
|
Hi All,
We are setting several custom stringProperties. However if we look in the TextMessage on the listener side we see that the stringProperties are empty.
The solution for us was to set the targetClient in WAS6 to JMS. This worked for our development environment. However if we do exactly the same thing for our Production environment it does not work.
So it looks like a configuration problem on the environment of MQ or WAS6. But i don't really have any idea where to look? Any one some suggestions to look at?
Thanks,
Gebrian |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Jul 01, 2008 2:36 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
We need more detailed information about your process.
Do you have the targetMatchingOption set to true?
Is it in a request reply scenario?
What is the definition of your target destination? etc...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
gebrian |
Posted: Wed Jul 02, 2008 12:36 am Post subject: |
|
|
Newbie
Joined: 30 Jun 2008 Posts: 3
|
I will add some code to explain the process.
Sender:
Code: |
private JmsOperations jmsTemplate; //using Spring JMSOperations
public void sendMessageToQueue(final CorrelationHeader header, final String payload, final CustomMessageType type) {
try {
jmsTemplate.send(new MessageCreator() {
public javax.jms.Message createMessage(Session session) throws JMSException {
javax.jms.Message message = session.createTextMessage(payload);
message = setProperties(message);
return message;
}
private javax.jms.Message setProperties(javax.jms.Message message) throws JMSException {
message.setStringProperty(MessagePropertyType.TYPE.name(), type.name());
message.setStringProperty(MessagePropertyType.CORRELATIONID.name(), header.getCorrelationData().getCorrelationId().toString());
message.setStringProperty(MessagePropertyType.SESSIONID.name(), header.getCorrelationData().getSessionId());
message.setStringProperty(MessagePropertyType.REQUESTCONTEXTID.name(), header.getRequestContextId().toString());
message.setJMSTimestamp(Calendar.getInstance().getTimeInMillis());
message.setStringProperty(MessagePropertyType.TOKEN.name(), header.getCorrelationData().getToken());
message.setStringProperty(MessagePropertyType.IPADDRESS.name(), header.getCorrelationData().getClientIPAddress());
message.setStringProperty(MessagePropertyType.HOSTNAME.name(), header.getCorrelationData().getHostName());
return message;
}
});
}
catch (RuntimeException ex) {
LOGGER.error("Unable to log message to Queue: " + ex.getMessage());
}
}
|
Receiver
Code: |
public class CustomMessageListener implements SessionAwareMessageListener {
private static final Log LOGGER = LogFactory.getLog(CustomMessageListener.class);
private ProcessingGroupDao processingGroupDao;
/**
* {@inheritDoc}
*/
public void onMessage(Message message, Session session) {
try {
if (message instanceof TextMessage) {
String messageText = ((TextMessage) message).getText();
String errorCode = null;
if (message.getStringProperty(CustomMessagePropertyType.TYPE.name()).equals(CustomMessageType.XML.name())) {
//do something
}
// do something
}
}
catch (JMSException e) {
LOGGER.error("Error parsing message", e);
}
catch (IOException e) {
LOGGER.error("Encoding is not supported", e);
e.printStackTrace();
}
catch (Exception e) {
LOGGER.error("Exception occured", e);
}
}
}
|
So we are putting a message on the queue with several properties set. On the listener side we are getting the message and looking for the properties. Thats it, so no request reply scenario. Both side are developed by the same team(offshore) this means we can change both sides as we wish.
In the above short example you will get a null-pointer because the message.getStringProperty is null. In our development WAS6 server that connects to MQ we have put the target client to JMS and it works nicely(default is MQ this will give the same problem as stated above).
I am unaware of the targetMatchingOption?
As a short solution we added the properties to the body and filter this on the clientside again this worked fine. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Jul 02, 2008 1:02 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
The big part you are missing is the lookup of the Destination and the definition of the destination.
Your code is fine but if your destination is defined with targetClient="MQ" or targetClient=1 it will matter little. The RFH header and all your custom properties will be stripped.
Don't know what you're doing with correlID as text property... I'd be very weary of that as it is a byte array.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
gebrian |
Posted: Thu Jul 03, 2008 2:55 am Post subject: |
|
|
Newbie
Joined: 30 Jun 2008 Posts: 3
|
Thanks for the reply. I will have a look at the lookup of the destination and the definition of the destination |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|