2015-05-18 41 views
0

我已經實現了一個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()); 
     } 
    } 

誰能幫助我?

+0

做 'TCP:// myBrokerHost:61616 /本地主機:60606'我得到以下錯誤: '爪哇。 net.ConnectException:無效的參數'我認爲問題是_localhost_的解決方案 – sirnino

回答

0

應該是一個要傳遞的getBrokerUrl()結果ActiveMQConnectionFactory例如:

ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost"); 
+0

如果我用「vm:// localhost」替換getrokerUrl(),我怎樣才能指定brokerUrl? – sirnino

+0

應爲u URL這樣的一個例子只 –

+0

所以該行應該成爲: 'ActiveMQConnectionFactory connectionFactory的新= ActiveMQConnectionFactory( 「VM:// myBrokerHost:61616 /本地主機:60606」);' 和生產者應從上myBrokerHost發佈港口60606? – sirnino

相關問題