Hi,
sorry, I forgot to note, that the resources in the context.xml and
web.xml files are replacements for the jndi.properties. I'm using
Tomcat's build-in JNDI.
It looks like you're using one Queue with the name listenerDestination.
So, try the following:
META-INF/context.xml:
<Context>
...
<Resource
name="jms/ConnectionFactory"
auth="Container"
type="org.apache.activemq.ActiveMQConnectionFactory"
description="JMS Connection Factory"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
brokerURL="ssl://localhost:32450"
brokerName="localhost"
useEmbeddedBroker="false" />
<Resource
name="jms/listenerDestination"
auth="Container"
type="org.apache.activemq.command.ActiveMQQueue"
factory="org.apache.activemq.jndi.JNDIReferenceFactory"
physicalName="dms.PublicLogQueue" />
...
</Context>
WEB-INF/web.xml:
...
<resource-env-ref>
<resource-env-ref-name>jms/ConnectionFactory</resource-env-ref-name>
<resource-env-ref-type>javax.jms.ConnectionFactory</resource-env-ref-type>
</resource-env-ref>
<resource-env-ref>
<resource-env-ref-name>jms/listenerDestination</resource-env-ref-name>
<resource-env-ref-type>javax.jms.Queue</resource-env-ref-type>
</resource-env-ref>
...
And in the code you can obtain the Destination using
try {
InitialContext ic = new InitialContext();
Context ctx = (Context) ic.lookup("java:comp/env");
ConnectionFactory cf = (ConnectionFactory)
ctx.lookup("jms/ConnectionFactory");
Connection conn = (Connection) cf.createConnection();
conn.start();
Session s = conn.createSession(false,
Session.CLIENT_ACKNOWLEDGE);
Destination d = (Destination)
ctx.lookup("jms/listenerDestination");
MessageProducer mp = s.createProducer(d);
mp.setDeliveryMode(DeliveryMode.PERSISTENT);
TextMessage tm = s.createTextMessage();
tm.setText("Foo");
mp.send(tm);
tm = s.createTextMessage();
tm.setText("Bar");
mp.send(tm);
conn.close();
} catch (Exception e) {
e.printStackTrace();
}
...
If you want to run ActiveMQ under Tomcat, not as standalone broker,
specify useEmbeddedBroker="true" in the context.xml.
The Resource tags can be also placed in the server.xml, but I have bad
experience with JDBC resources there, so I didn't try it.
Try the configuration above. This must work for you!
PETR
On 6/2/06, Maciej Łabędzki <[EMAIL PROTECTED]> wrote:
Hadraba Petr napisał(a):
> Hi Maciej,
>
> I'm connecting from Tomcat to ActiveMQ with this configuration:
>
Thx, but how it corresponds to my jndi.properties file?
How should I form my configuration files (context.xml, web.xml)?
jndi.properties:
---------------
java.naming.factory.initial =
org.activemq.jndi.ActiveMQInitialContextFactory
brokerURL =ssl://localhost:32450
queue.listenerDestination = dms.PublicLogQueue
Maciej
---------------------------------------------------------------------
To start a new topic, e-mail: [email protected]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
Petr Hadraba
graphic artist and software designer
http://people.hadraba-soft.com/~petr
hadrabap AT bluetone DOT cz