adbdkb
adbdkb

Reputation: 2161

How to programmatically retrieve JMSMessage Class value from a JMS message

I am using JMS to put a message on MQ and an MDB that uses JMS classes ( not MQ specific classes ) to read and process the message.

When I print the message ( which uses the message's toString() method, I get the output below

I want to programmatically retrive the value of 'jms_text', 'jms_bytes', etc. as the case maybe.

How can I achieve that? I tried to find the properties, but that also did not give me this information.

+++ SAMPLE MDB: Text Message => Testing sending message to error queue
[3/15/14 8:54:51:988 EDT] 00000323 SystemOut     O Received message: 

 JMSMessage class: jms_text
 --------------------------
  JMSType:          null
  JMSDeliveryMode:  2
  JMSExpiration:    0
  JMSPriority:      4
  JMSMessageID:     ID:414d5120514458362020202020202020cc070d53025e4d22
  JMSTimestamp:     1394803436074
  JMSCorrelationID: null
  JMSDestination:   queue:///XX.MY.ERR.QUEUE
  JMSReplyTo:       null
  JMSRedelivered:   false
    JMSXAppID: WebSphere MQ Client for Java
    JMSXDeliveryCount: 1
    JMSXUserID: b8320      
    JMS_IBM_Character_Set: UTF-8
    JMS_IBM_Encoding: 273
    JMS_IBM_Format: MQSTR  
    JMS_IBM_MsgType: 8
    JMS_IBM_PutApplType: 28
    JMS_IBM_PutDate: 20140314
    JMS_IBM_PutTime: 13235615
Testing sending message to error queue 

Thank you for any help

Upvotes: 0

Views: 2318

Answers (1)

Shashi
Shashi

Reputation: 15263

Updated:

You can use the instanceof operator to determine the type of message. JMS defines five types of messages Text, Stream, Bytes, Map and Object. So you can check as below:

if (rcvdMessage instanceof JMSTextMessage)
    msgType = "jms_text";
else if (rcvdMessage instanceof JMSStreamMessage)
    msgType = "jms_stream";
else if (rcvdMessage instanceof JMSMapMessage)
    msgType = "jms_map";
else if (rcvdMessage instanceof JMSBytesMessage)
    msgType = "jms_bytes";
else if (rcvdMessage instanceof JMSObjectMessage)
    msgType = "jms_object";
else
    msgType = "jms_none";

Upvotes: 1

Related Questions