blob: 2bd7d761ef56e65aec7be21e195345545eac3696 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
<?xml version="1.0" encoding="utf-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<chapter>
<title>
Using Qpid with other JNDI Providers
</title>
<section role="h2" id="UsingQpidwithotherJNDIProviders-HowtouseaJNDIProvider">
<title> How to use a JNDI Provider </title>
<para>
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 ....
</para>
<para>
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:
</para>
<itemizedlist>
<listitem><para>Apache's <xref linkend="qpid_index"/>
which provides an LDAP JNDI implementation
</para></listitem>
</itemizedlist>
<itemizedlist>
<listitem>
<para>OR the SUN JNDI SPI for the FileSystem which can be
downloaded from <xref linkend="qpid_index"/>
</para>
<itemizedlist>
<listitem><para>Click : Download JNDI 1.2.1 & More button
</para></listitem>
<listitem><para>Download: File System Service Provider, 1.2 Beta 3
</para></listitem>
<listitem><para>and then add the two jars in the lib dir to your class path.
</para></listitem>
</itemizedlist>
</listitem>
</itemizedlist>
<para>
There are two steps to using JNDI objects.
</para>
<itemizedlist>
<listitem><para>Bind : Which stores a reference to a JMS
Object in the provider.</para></listitem>
<listitem><para>Lookup : Which tries to retrieve the
reference and create the JMS Object. </para></listitem>
</itemizedlist>
<para>
There are two objects that would normally be stored in JNDI.
</para>
<itemizedlist>
<listitem><para>A ConnectionFactory
</para></listitem>
<listitem><para>A Destination (Queue or Topic)
</para></listitem>
</itemizedlist>
<section role="h3" id="UsingQpidwithotherJNDIProviders-Binding">
<title>
Binding
</title>
<para>
Then you need to setup the values that the JNDI provider will
used to bind your references, something like this:
</para>
<example>
<title>Setup JNDI</title>
<programlisting>
Hashtable env = new Hashtable(11);
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.fscontext.RefFSContextFactory");
env.put(Context.PROVIDER_URL,LOCAL_FILE_PATH_FOR_STORING_BINDS_PATH_MUST_EXIST);
</programlisting>
</example>
<para>
These values are then used to create a context to bind your
references.
</para>
<example>
<title>Perform Binding of ConnectionFactory</title>
<programlisting>
try
{
Context ctx = new InitialContext(env);
// Create the object to be bound in this case a ConnectionFactory
ConnectionFactory factory = null;
try
{
factory = new AMQConnectionFactory(CONNECTION_URL);
try
{
ctx.bind(binding, factory);
}
catch (NamingException e)
{
//Handle problems with binding. Such as the binding already exists.
}
}
catch (URLSyntaxException amqe)
{
//Handle any exception with creating ConnnectionFactory
}
}
catch (NamingException e)
{
//Handle problem creating the Context.
}
</programlisting>
</example>
<para>
To bind a queue instead simply create a AMQQueue object and use
that in the binding call.
</para>
<example>
<title> Bind a AMQQueue</title>
<programlisting>
AMQQueue queue = new AMQQueue(QUEUE_URL);
ctx.bind(binding, queue);
</programlisting>
</example>
</section>
<section role="h3" id="UsingQpidwithotherJNDIProviders-Lookup">
<title>
Lookup
</title>
<para>
You can then get a queue connection factory from the JNDI
context.
</para>
<example>
<title> Perform Binding of ConnectionFactory</title>
<programlisting>
ConnectionFactory factory;
try
{
factory= (ConnectionFactory)ctx.lookup(binding);
}
catch (NamingException e)
{
//Handle problems with lookup. Such as binding does not exist.
}
</programlisting>
</example>
<para>
Note that you need not cast the bound object back to an
AMQConnectionFactory so all your current JMS apps that
use JNDI can start using Qpid straight away.
</para>
<!--h2-->
</section>
<section role="h2" id="UsingQpidwithotherJNDIProviders-HowtocreateaTopicConnectionFactoryandQueueConnectionFactory"><title>
How to create a TopicConnectionFactory and
QueueConnectionFactory
</title>
<para>
AMQConnectionFactory implements TopicConnectionFactory and
QueueConnectionFactory as well as the ConnectionFactory.
</para>
<!--h3-->
</section>
<!--h2-->
</section>
</chapter>
|