Question

I am trying to write a simple Java program that reads from JBossMQ's jms_messages table using JDBC. I am using JBoss 4.0.4.GA.

I can get the as far as getting a SpyMessage, but how can I get the actual message content (which is an Object in the particular case I'm looking at).

I have a result set "rs" from this statement:

SELECT messageid, messageblob FROM jms_messages WHERE DESTINATION LIKE 'TOPIC.MyTopic%' limit 3"

and then I do this (based on JBoss code):

long messageid = rs.getLong(1);
SpyMessage message = null;
byte[] st = rs.getBytes(2);
ByteArrayInputStream baip = new ByteArrayInputStream(st);
ObjectInputStream ois = new ObjectInputStream(baip);

message = SpyMessage.readMessage(ois);
message.header.messageId = messageid;

String jmstype = message.getJMSType();
String jms_message_id = message.getJMSMessageID();
System.out.println("jmstype=" +jmstype);
System.out.println("jms_message_id=" +jms_message_id);

String propertyName;
Enumeration e = message.getPropertyNames();
while (e.hasMoreElements())
{
    propertyName = (String)e.nextElement();
    System.out.println("property name = " +propertyName);
}

but I get no properties printed and I don't know how to get my actual object from the SpyMessage (actually a SpyObjectMessage). I'd be grateful for any pointers.

I've tried asking this question on the JBoss forum without reply, so I'm hoping for better luck here.

Thanks.

Was it helpful?

Solution

Sorry - the answer was so obvious I'm not really sure what I was thinking when I posted the question - simply:

Object objMessage = ((SpyObjectMessage)message).getObject();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top