Forum Stats

  • 3,757,793 Users
  • 2,251,267 Discussions
  • 7,869,917 Comments

Discussions

reading and setting JMSXUserID

886634
886634 Member Posts: 14
edited Nov 8, 2011 6:20AM in Java Message Service (JMS)
Hi,

I have a question regarding the proper usage for standard properties that start with JMSX. In particular, I want to be able to read the JMSXUserID property for each message. However, after receiving a message, the JMSXUserID property comes out to be null. The following line is the code I am using:

System.out.println("JMSXUserID: " + message.getStringProperty("JMSXUserID"));

Am I supposed to set the JMSXUserID when I first send the message? It works when I add the following line:

message.setStringProperty("JMSXUserID", "hostName");

However, in the MQ Developer's guide for Java Clients, it states:

"The JMS specification defines certain standard properties, listed in Table 2–7 . By convention, the names of all such standard properties begin with the letters JMSX; names of this form are reserved and must not be used by a client application for its own custom message properties. "

With that said, I would have expected an exception thrown after I set the JMSXUserID to be "hostName". Can someone please clarify how I am supposed to access these standard JMSX properties?

Answers

  • DrClap
    DrClap Member Posts: 25,479
    Could you go back a step and explain why you want to read that property? After all, if nobody is setting it then there isn't much point in trying to read it. And if you're writing a client application and you want a custom property to hold a "user ID", then you could certainly choose some other name for that property.
  • 886634
    886634 Member Posts: 14
    I have an application that receives messages from multiple senders and I need to know who sent each message. Yes, I can create my own message property but thought I should use what's already provided to reduce the cost of overhead.

    JMSX is already provided as a standard property. Are these properties something I am supposed to set and change within the client application? Or are these properties automatically set by the connection factory? If that's the case, why is the JMSXUserID coming out to null?

    Thanks
  • DrClap
    DrClap Member Posts: 25,479
    Cost of overhead? You're asserting that there is some massive overhead involved with naming a property "userid" instead of "JMSXUserId"? I find it amazing, the reasons that people dream up to avoid doing something reasonable and ordinary.

    I'm assuming that ConnectionFactories which require authentication would use the JMSXUserID property, although I have no experience with that. However since it appears that you already know the user ID, so just use a property named "userid" to send it along with the message.
  • ramp
    ramp Member Posts: 2,358
    883631 wrote:
    Hi,

    I have a question regarding the proper usage for standard properties that start with JMSX. In particular, I want to be able to read the JMSXUserID property for each message. However, after receiving a message, the JMSXUserID property comes out to be null. The following line is the code I am using:
    Just to add to the answers already provided, many of the standard properties (headers) are overridden by the jms runtime and that would explain the null value. As already suggested, just use a custom property. There is negligible overhead for a string/value pair.

    cheers.
  • The JMSX* properties are intended to be set by the JMS provider, not the client program. According to the JMS specification it is optional whether JMS providers support this property, so you would need to consult the documentation for your chosen JMS provider.

    You mentioned that you were using GlassFish MQ. This doesn't support the JMSXUserID property by default, as you discovered. However you can enable it by setting the connection factory property imqSetJMSXUserID to "true" for the sending connection.

    This will then set the JMSXUserID property of the message to the username of the connection being used to send the message. This will be the username that you passed into createConnection(user,password). if you used createConnection() with no arguments this will be set to "guest".

    This is documented in the GlassFish Message Queue Administration Guide at
    http://download.oracle.com/docs/cd/E18930_01/html/821-2438/aeooe.html#aeooj

    I'm not surprised you missed this. You looked in the GlassFish Message Queue Developers' Guide for Java Clients, which lists the property names but doesn't mention that if you want to use these properties you need to enable them. There needs to be a cross-reference added. I've logged a documentation bug http://java.net/jira/browse/MQ-128

    Incidentally, the best place to ask questions about GlassFish MQ is the forum dedicated for that purpose:
    3876

    Nigel
This discussion has been closed.