O'Reilly - Java Message Service
O'Reilly - Java Message Service
O'Reilly - Java Message Service
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>Java</strong> <strong>Message</strong> <strong>Service</strong><br />
The constructor of the Chat class starts by obtaining a connection to the JNDI naming<br />
service used by the JMS server:<br />
// Obtain a JNDI connection<br />
Properties env = new Properties( );<br />
// ... specify the JNDI properties specific to the vendor<br />
InitialContext jndi = new InitialContext(env);<br />
Creating a connection to a JNDI naming service requires that a<br />
javax.naming.InitialContext object be created. An InitialContext is the starting point<br />
for any JNDI lookup - it's similar in concept to the root of a filesystem. The<br />
InitialContext provides a network connection to the directory service that acts as a root<br />
for accessing JMS administered objects. The properties used to create an InitialContext<br />
depend on which JMS directory service you are using. The code used to create a JNDI<br />
InitialContext in BEA's Weblogic naming service, for example, would look something<br />
like this:<br />
Properties env = new Properties( );<br />
env.put(Context.SECURITY_PRINCIPAL, "guest");<br />
env.put(Context.SECURITY_CREDENTIALS, "guest");<br />
env.put(Context.INITIAL_CONTEXT_FACTORY,<br />
"weblogic.jndi.WLInitialContextFactory");<br />
env.put(Context.PROVIDER_URL, "t3://localhost:7001");<br />
InitialContext jndi = new InitialContext(env);<br />
When SonicMQ is used in combination with a third party LDAP directory service, the<br />
connection properties would be very different. For example, the following shows how a<br />
SonicMQ JMS client would use JNDI to access JMS administered objects stored in a<br />
LDAP directory server:<br />
Properties env = new Properties( );<br />
env.put(Context.SECURITY_PRINCIPAL, "guest");<br />
env.put(Context.SECURITY_CREDENTIALS, "guest");<br />
env.put(Context.INITIAL_CONTEXT_FACTORY,<br />
"com.sun.jndi.ldap.LdapCtxFactory");<br />
env.put(Context.PROVIDER_URL,<br />
"ldap://localhost:389/o=acme.com");<br />
InitialContext jndi = new InitialContext(env);<br />
Alternatively, the InitialContext( ) can be created without<br />
properties (no-arg constructor). In this case JNDI will read the<br />
vendor-specific JNDI properties from a special file in the classpath<br />
named jndi.properties. This eliminates provider-specific code in JMS<br />
clients, making them more portable.<br />
23