diff options
Diffstat (limited to 'src/documentation/content/xdocs/Using Qpid with other JNDI Providers.html')
-rwxr-xr-x | src/documentation/content/xdocs/Using Qpid with other JNDI Providers.html | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/src/documentation/content/xdocs/Using Qpid with other JNDI Providers.html b/src/documentation/content/xdocs/Using Qpid with other JNDI Providers.html new file mode 100755 index 0000000000..0b46fc3a3a --- /dev/null +++ b/src/documentation/content/xdocs/Using Qpid with other JNDI Providers.html @@ -0,0 +1,137 @@ +<html> + <head> + <title>Apache Qpid : Using Qpid with other JNDI Providers</title> + <link rel="stylesheet" href="styles/site.css" type="text/css" /> + <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> + </head> + + <body> + <table class="pagecontent" border="0" cellpadding="0" cellspacing="0" width="100%" bgcolor="#ffffff"> + <tr> + <td valign="top" class="pagebody"> + <div class="pageheader"> + <span class="pagetitle"> + Apache Qpid : Using Qpid with other JNDI Providers + </span> + </div> + <div class="pagesubheading"> + This page last changed on Jun 22, 2007 by <font color="#0050B2">ritchiem</font>. + </div> + + +<h2><a name="UsingQpidwithotherJNDIProviders-HowtouseaJNDIProvider"></a>How to use a JNDI Provider</h2> + +<p>Qpid will work with any JNDI provider capable of storing Java objects. We have a task to add our own initial context factory, but until that's available ....</p> + +<p>First you must select a JNDI provider to use. If you aren't already using an application server (i.e. Tomcat ?) which provides JNDI support you could consider using either:</p> +<ul> + <li>Apache's <a href="http://directory.apache.org/subprojects/apacheds/index.html" title="Visit page outside Confluence">Directory</a> which provides an LDAP JNDI implementation</li> +</ul> + + +<ul> + <li>OR the SUN JNDI SPI for the FileSystem which can be downloaded from <a href="http://java.sun.com/products/jndi/downloads/index.html" title="Visit page outside Confluence">http://java.sun.com/products/jndi/downloads/index.html</a></li> +</ul> + + +<ul class="alternate" type="square"> + <li>Click : Download JNDI 1.2.1 & More button</li> + <li>Download: File System Service Provider, 1.2 Beta 3</li> + <li>and then add the two jars in the lib dir to your class path.</li> +</ul> + + +<p>There are two steps to using JNDI objects.</p> +<ul class="alternate" type="square"> + <li>Bind : Which stores a reference to a JMS Object in the provider.</li> + <li>Lookup : Which tries to retrieve the reference and create the JMS Object.</li> +</ul> + + +<p>There are two objects that would normally be stored in JNDI.</p> +<ul class="alternate" type="square"> + <li>A ConnectionFactory</li> + <li>A Destination (Queue or Topic)</li> +</ul> + + +<h3><a name="UsingQpidwithotherJNDIProviders-Binding"></a>Binding</h3> + +<p>Then you need to setup the values that the JNDI provider will used to bind your references, something like this:</p> +<div class="code" style="border-style: solid; "><div class="codeHeader" style="border-bottom-style: solid; "><b>Setup JNDI</b></div><div class="codeContent"> +<pre class="code-java">Hashtable env = <span class="code-keyword">new</span> Hashtable(11);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,<span class="code-quote">"com.sun.jndi.fscontext.RefFSContextFactory"</span>);
+ env.put(Context.PROVIDER_URL,LOCAL_FILE_PATH_FOR_STORING_BINDS_PATH_MUST_EXIST);</pre> +</div></div> +<p>These values are then used to create a context to bind your references.</p> +<div class="code" style="border-style: solid; "><div class="codeHeader" style="border-bottom-style: solid; "><b>Perform Binding of ConnectionFactory</b></div><div class="codeContent"> +<pre class="code-java"><span class="code-keyword">try</span>
+{
+ Context ctx = <span class="code-keyword">new</span> InitialContext(env);
+
+ <span class="code-comment">// Create the object to be bound in <span class="code-keyword">this</span> <span class="code-keyword">case</span> a ConnectionFactory
+</span> ConnectionFactory factory = <span class="code-keyword">null</span>;
+
+ <span class="code-keyword">try</span>
+ {
+ factory = <span class="code-keyword">new</span> AMQConnectionFactory(CONNECTION_URL);
+ <span class="code-keyword">try</span>
+ {
+ ctx.bind(binding, factory);
+ }
+ <span class="code-keyword">catch</span> (NamingException e)
+ {
+ <span class="code-comment">//Handle problems with binding. Such as the binding already exists.
+</span> }
+ }
+ <span class="code-keyword">catch</span> (URLSyntaxException amqe)
+ {
+ <span class="code-comment">//Handle any exception with creating ConnnectionFactory
+</span> }
+}
+<span class="code-keyword">catch</span> (NamingException e)
+{
+ <span class="code-comment">//Handle problem creating the Context.
+</span>}</pre> +</div></div> +<p>To bind a queue instead simply create a AMQQueue object and use that in the binding call.</p> +<div class="code" style="border-style: solid; "><div class="codeHeader" style="border-bottom-style: solid; "><b>Bind a AMQQueue</b></div><div class="codeContent"> +<pre class="code-java">AMQQueue queue = <span class="code-keyword">new</span> AMQQueue(QUEUE_URL);
+ctx.bind(binding, queue);</pre> +</div></div> + +<h3><a name="UsingQpidwithotherJNDIProviders-Lookup"></a>Lookup</h3> + +<p>You can then get a queue connection factory from the JNDI context.</p> +<div class="code" style="border-style: solid; "><div class="codeHeader" style="border-bottom-style: solid; "><b>Perform Binding of ConnectionFactory</b></div><div class="codeContent"> +<pre class="code-java">ConnectionFactory factory;
+<span class="code-keyword">try</span>
+{
+ factory= (ConnectionFactory)ctx.lookup(binding);
+}
+<span class="code-keyword">catch</span> (NamingException e)
+{
+ <span class="code-comment">//Handle problems with lookup. Such as binding does not exist.
+</span>}</pre> +</div></div> +<p>Note that you need not cast the bound object back to an <tt>AMQConnectionFactory</tt> so all your current JMS apps that use JNDI can start using Qpid straight away.</p> + + +<h2><a name="UsingQpidwithotherJNDIProviders-HowtocreateaTopicConnectionFactoryandQueueConnectionFactory"></a>How to create a TopicConnectionFactory and QueueConnectionFactory</h2> + +<p>AMQConnectionFactory implements TopicConnectionFactory and QueueConnectionFactory as well as the ConnectionFactory.</p> + + + </td> + </tr> + </table> + <table border="0" cellpadding="0" cellspacing="0" width="100%"> + <tr> + <td height="12" background="border/border_bottom.gif"><img src="border/spacer.gif" width="1" height="1" border="0"/></td> + </tr> + <tr> + <td align="center"><font color="grey">Document generated by Confluence on Apr 22, 2008 02:47</font></td> + </tr> + </table> + </body> +</html>
\ No newline at end of file |