0

How would you implement a Content Enricher in WebSphere MQ using Java?

Given an existing input message is provided from a queue, here are some of my ideas, none of which satisfies me:

  1. Deep-clone the message object. Here is an explanation of how it could be done, but I can't find either clone() or serialize() methods for the javax.jms.Message class.
  2. Take the original message, set the additional properties using setXXXProperty() and send it forward. This throws an exception suggesting that the message is read-only.
  3. Create a new message, iterate over properties of the existing message and set them to the new message. getPropertyNames() can help to do this, but it says nothing about types of properties, so this information will be lost.
Community
  • 1
  • 1
Pavel
  • 150
  • 6
  • 1 - No. there is others Message types (TextMessage, ByteMessage ...). 2. Optimal. 3 No. Description and implementation from apache camel http://camel.apache.org/content-enricher.html – Anton N Feb 13 '14 at 03:16

1 Answers1

1

In short, IBM integration bus can do it in a message flow... But let me provide a WMQ Java answer also:

The message object that is received can be modified and sent back ... All you need to do is to read all the stuff you need from that message to some java object. For example you can use a Map for Properties. Then call clearProperties() and then set the modified properties. The issue of readonly goes away after calling clearProperties() (http://docs.oracle.com/javaee/5/api/javax/jms/Message.html#clearProperties%28%29)

So a mix of (2) and (3) can help in solving the problem.

Neeraj Krishna
  • 1,527
  • 2
  • 16
  • 22
  • Message Broker for current task is overkill. – Anton N Feb 13 '14 at 03:17
  • Neeraj, you were right. A correction to approach #2: Instead of using setXXXProperty() where XXX is the name of a type, it is recommended to use setObjectProperty(). This ensures the property preserves its type. – Pavel Feb 13 '14 at 11:02