Я хочу изучить приложение JMS, используя Active MQ.
Итак, скачал apache-activemq-5.5.1 и запустил сервер
и нашел пример кода, но не работает.Почему происходит следующее исключение?
Примечание: я добавил библиотеку activemq в свой проект, и библиотека содержит модуль org.slf4j
import javax.jms.*;
import org.apache.activemq.ActiveMQConnectionFactory;
import javax.jms.MessageListener;
//JMS Producer
public class JMSProducer {
public void produce() {
String url = "tcp://localhost:61616";
ConnectionFactory factory = new ActiveMQConnectionFactory(url);
try {
Connection connection = factory.createConnection();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic("TestTopic");
MessageProducer producer = session.createProducer(topic);
TextMessage msg = session.createTextMessage();
msg.setText("Hello JMS World");
producer.send(msg);
}
catch(JMSException exp) {
}
}
}
//JMS Consumer
public class JMSConsumer {
public void consume() {
String url = "tcp://localhost:61616";
ConnectionFactory factory = new ActiveMQConnectionFactory(url);
try {
Connection connection = factory.createConnection();
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic("TestTopic");
MessageConsumer consumer = session.createConsumer(topic);
JMSMessageListener listener = new JMSMessageListener();
consumer.setMessageListener(listener);
connection.start();
}
catch(JMSException exp) {
}
}
}
//JMS Message Listener
public class JMSMessageListener implements MessageListener {
@Override
public void onMessage(javax.jms.Message msg) {
System.out.println(msg.toString());
}
}