Hi... I have one web application (war) file.
Which contains
- one java class (which contains 2 method, one which produces 10 message and one which consumes that is read 10 messages.)
- one Controller Servlet
- two JSP. Produce.jsp and consume.jsp
- jndi.properties file.
- I am using ActiveMQ as message broker.
I can produce the messages but i'm not able to consume messages, i'm getting the following error
############ org.apache.activemq.jndi.ActiveMQInitialContextFactory
Queue Name : MyQueue
JNDI API lookup failed: javax.naming.NameNotFoundException: Name QueueConnectionFactory is not bound in this Context
- Pausing Coyote HTTP/1.1 on http-8080
- Stopping service Catalina
- SessionListener: contextDestroyed()
- ContextListener: contextDestroyed()
- SessionListener: contextDestroyed()
- ContextListener: contextDestroyed()
- Waiting for 1 instance(s) to be deallocated
- Waiting for 1 instance(s) to be deallocated
- Waiting for 1 instance(s) to be deallocated
- WebLM Server: WebLMServlet - webLMDestroy()
- WebLM Server: Successfully stopped PeriodicManager.
- WebLM Server: Successfully stopped PeakUsageHistoryTimer.
- WebLM Server: Number of products for which peak usage data is to be saved: 0
- WebLM Server: Number of products for which peak usage data could not be saved: 0
- WebLM Server: Tried to save PeakUsageHistory for all products.
- WebLM Server: License server destroyed
- Stopping Coyote HTTP/1.1 on http-8080
- Failed shutdown of Apache Portable Runtime
Strange thing is that when i run my consumer from a simple java application which contains main method which consumes the messages,
Its working fine. but only with web application i'm not able to consume messages.
Bellow is the content of jndi.properties file
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
java.naming.provider.url = tcp://localhost:61616
queue.MyQueue = MyQueue
topic.MyTopic = MyTopic
Bellos is the code for consuming messages
public void readMessage(String queueName) throws Exception{
props.load(getClass().getClassLoader().getResourceAsStream("jndi.properties"));
System.out.println("############ " + props.getProperty("java.naming.factory.initial"));
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueReceiver queueReceiver = null;
TextMessage message = null;
System.out.println("Queue Name : " + queueName);
/*
* Create a JNDI API InitialContext object if none exists
* yet.
*/
try {
jndiContext = new InitialContext();
}catch (NamingException e) {
System.out.println("Could not create JNDI API context: " + e.toString());
System.exit(1);
}
/*
* Look up connection factory and queue. If either does
* not exist, exit.
*/
try {
queueConnectionFactory = (QueueConnectionFactory)jndiContext.lookup("QueueConnectionFactory");
queue = (Queue) jndiContext.lookup(queueName);
}catch (NamingException e) {
System.out.println("JNDI API lookup failed: " +
e.toString());
System.exit(1);
}
/*
* Create connection.
* Create session from connection; false means session is
* not transacted.
* Create receiver, then start message delivery.
* Receive all text messages from queue until
* a non-text message is received indicating end of
* message stream.
* Close connection.
*/
try {
queueConnection = queueConnectionFactory.createQueueConnection();
queueSession = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
queueReceiver = queueSession.createReceiver(queue);
queueConnection.start();
while (true) {
Message m = queueReceiver.receive(1);
if (m != null) {
if (m instanceof TextMessage) {
message = (TextMessage) m;
String textMessage = message.getText();
try{
if (!(textMessage==null || textMessage=="")){
messageProcessor(textMessage);
}
System.out.println("Reading message: " + textMessage);
}catch(Exception e){
e.printStackTrace();
}
}
}
}
} catch (JMSException e) {
System.out.println("Exception occurred: " + e.toString());
} finally {
if (queueConnection != null) {
try {
queueConnection.close();
} catch (JMSException e) {}
}
}
}
f anybody can help me out, i will be thankful.
With warm regards,
Amie
Edited by: Amie on Jul 9, 2008 11:14 AM