问答详情
源自:4-3 队列模式的消息演示

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

}

}


提问者:qq_Sebtimental丶_23564747 2018-08-03 09:41

个回答