I am new to JMS
and Activemq
.using Google and stack overflow help I am sending messages from my Java program to Activemq
using the following code.
package PackageName;
import java.io.IOException;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.activemq.ActiveMQConnectionFactory;
//@SuppressWarnings("serial")
public class MessageProducer extends HttpServlet {
@Override
protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {
try {
//created ConnectionFactory object for creating connection
ConnectionFactory factory = new ActiveMQConnectionFactory("admin","admin","tcp://localhost:61617");
//Establish the connection
Connection connection = factory.createConnection();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createQueue("MessageTesing123");
//Added as a producer
javax.jms.MessageProducer producer = session.createProducer(queue);
// Create and send the message
TextMessage msg = session.createTextMessage();
msg.setText("TestMessage3");
producer.send(msg);
} catch (Exception e) {
// TODO: handle exception
}
}
}
If I run this .java file using Apache Tomcat
,it's working fine but I am getting the following warnings.
log4j:WARN No appenders could be found for logger (org.apache.activemq.transport.WireFormatNegotiator).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
How can I fix this.
Thanks.