我已經實現了一個JMS生產者和一個消費者,它們被部署在DMZ中的兩個不同的主機上。 Here我讀了如何爲生產者定義自定義主機和端口。但我不明白我必須把這條線放在哪裏。自定義ActiveMQ生產者端口
這裏是我的代碼:
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());
}
}
誰能幫助我?
做 'TCP:// myBrokerHost:61616 /本地主機:60606'我得到以下錯誤: '爪哇。 net.ConnectException:無效的參數'我認爲問題是_localhost_的解決方案 – sirnino