Cannot send, channel has already failed: tcp://127.0.0.1:8161

来源:4-3 队列模式的消息演示

qq_Sebtimental丶_23564747

2018-08-03 09:41

运行这段代码出现这个问题

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();

}

}


写回答 关注

3回答

Java消息中间件

使用Java消息中间件处理异步消息

54146 学习 · 144 问题

查看课程

相似问题