【发布时间】:2015-05-18 10:05:15
【问题描述】:
我已经实现了一个 JMS 生产者和消费者,它们部署在两个不同的主机中,都在一个 DMZ 中。 Here 我阅读了如何为生产者定义自定义主机和端口。但我不明白我必须把那条线放在哪里。
这是我的代码:
Connection connection = null;
try{
System.out.println("Connecting to "+getBrokerUrl());
connection = (new ActiveMQConnectionFactory(getBrokerUrl())).createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Topic topic = session.createTopic(this.topicName);
TextMessage txtMsg = session.createTextMessage();
txtMsg.setText(msg);
txtMsg.setJMSType(msgType);
MessageProducer producer = session.createProducer(topic);
producer.send(txtMsg);
}
catch(Exception e){
System.out.println("Error: " + e.getMessage());
}
finally{
try{
connection.close();
}
catch(JMSException je){
System.out.println("Unable to close connection: "+je.getMessage());
}
}
谁能帮帮我?
【问题讨论】:
-
Doing
tcp://myBrokerHost:61616/localhost:60606我得到以下错误:java.net.ConnectException: Invalid Argument我认为问题是 localhost 的分辨率
标签: java jms port activemq producer