我是新手JMS
,Activemq
使用 Google 和堆栈溢出帮助我正在从我的 Java 程序发送消息以Activemq
使用以下代码。
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
}
}
}
如果我使用 .java 运行这个文件Apache Tomcat
,它工作正常,但我收到以下警告。
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.
我怎样才能解决这个问题。
谢谢。