mainstringargs
mainstringargs

Reputation: 14411

Trace where JMS message came from

Is there any way in the javax.jms.Message API to get the information about where the Message came from (from a onMessage(Message msg)) call?

I am dealing with a large chunk of new code, and I can see where the messages are coming in, but it would be very helpful to find a trace of the stack where the messages are coming from.

The trace I get is:

java.lang.Exception: Stack trace
    at java.lang.Thread.dumpStack(Thread.java:1206)
    at aaa.switch.serverobjects.SVSBean.activateDevice(SVSBean.java:377)
    at aaa.serverobjects.DeviceControlAdapter.activate(DeviceControlAdapter.java:659)
    at aaa.voiceswitch.serverobjects.SVSBean.activate(SVSBean.java:352)
    at aaa.service.DeviceControlServiceJMSMessageListener$1.run(DeviceControlServiceJMSMessageListener.java:237)
    at java.lang.Thread.run(Thread.java:619)

Which obviously just goes back to java.lang.thread which doesnt really help.

Upvotes: 1

Views: 651

Answers (2)

AlexR
AlexR

Reputation: 115388

I agree that it is impossible but here is what I'd do. If code that sends message is encapsulated in one class (e.g. class MyJMSSender) just add special message property (e.g. "stacktrace") and put there value

Arrays.asList(new Throwable().getStackTrace()).replace(", ", "\n")

You will be able to print this property on receiving side and know where the message came from.

Upvotes: 2

Robin
Robin

Reputation: 24282

Not unless your JMS implementation is embedded within your current JVM and effectively single threaded. I don't know of any implementation that operates like this and it certainly would be atypical since JMS is usually used for passing messages between applications.

Since this is the typical case, your stack will be limited to your current thread in your VM. I don't think there is any way to get the stack to include information from another application(s) (i.e. the JMS server and sending application).

Upvotes: 2

Related Questions