Cannot send, channel has already failed: tcp://127.0.0.1:8161
运行这段代码出现这个问题
public class AppProducer {
private static final String url = "tcp://127.0.0.1:8161";
private static final String queueName = "queue-test";
public static void main(String[] args) throws JMSException {
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
Connection connection = connectionFactory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(queueName);
MessageProducer producer = session.createProducer(destination);
for (int i = 0; i < 100; i++) {
TextMessage textMessage = session.createTextMessage("test" + i);
producer.send(textMessage);
System.out.println("发送消息" + textMessage.getText());
}
connection.close();
}
}