Uri
Uri

Reputation: 89829

Is there a way to get the origin IP address from a JMS message?

I have a system in which different server processes are handling requests passed as JMS messages from various clients via a JMS broker.

I am trying to identify the source of the messages. Is there a way to get the IP or some identifying information about the origin ?

Clarification: I already have the client deployed by unknown users, so I'm trying to avoid changing message classes...

Upvotes: 6

Views: 5623

Answers (7)

Marcel
Marcel

Reputation: 3817

Short answer: NO

Upvotes: -1

iMack
iMack

Reputation: 39213

Using glassfish, if you look at the getJMSMessageID() of the message, you should see a string to the effect of "ID:40-192.168.0.242(f5:62:c6:58:22:6f)-52506-122885191641". It appears as though the IP is a substring of the message id.

Please note that this is what I can see under our setup, so there may be other factors at play (ie. spring), but I know that string wasn't created by us programatically.

Upvotes: 0

James Strachan
James Strachan

Reputation: 9198

There is an optional JMS header mentioned in the JMS specification called JMSXUserID which which identifies the user sending a message (which the broker validates and ensures is correct to avoid spoofing) which some JMS providers support.

For example here is how to enable it in Apache ActiveMQ

Upvotes: 3

Lyndon
Lyndon

Reputation:

Its depends on your JMS Server. Some servers have Admin tools/API's that allow you to view connection details.

Upvotes: 0

John M
John M

Reputation: 13239

If you control the code of the clients sending the messages, you could invent some property name, say "IPOfSender", and include that property on every message with Message.setStringProperty().

// client code
String myIPString = ...;
Message m = session.createTextMessage();
m.setStringProperty("IPOfSender", myIPString);
...

Upvotes: 0

fawce
fawce

Reputation: 822

If you have control over the construction of the messages being sent, you can always add the IP address to the message as a property. Then you could check for the value with the getStringProperty method on Message.

Upvotes: 0

svlists
svlists

Reputation: 702

I do not believe so. At least I was not able to find a way.

If you need to send a reply back to the source of the message, you can have the sender set the "JMSReplyTo" property and reply back to that destination.

Or, you could change your messaging schema slightly and embed the source information message itself. The sender would identify himself in the message and the receive could read it from there.

Upvotes: 1

Related Questions