2016-04-25 373 views
0

我是ActiveMQ的新手。我使用本地機器上的默認設置在Windows上運行ActiveMQ服務器。我試圖創建一個簡單的隊列來測試發送消息。無法創建ActiveMQ隊列或使用java發送消息

public class Foo { 

    public static void main(String[] args) { 
     new Foo().send(); 
    } 

    public void send(){  
     try { 
      ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost:61616"); 
      Connection connection = connectionFactory.createConnection(); 
      connection.start(); 

      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); 
      Destination destination = session.createQueue("TESTQUEUE"); 
      MessageProducer producer = session.createProducer(destination); 
      producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); 

      TextMessage message = session.createTextMessage("MESSAGE123"); 
      producer.send(message); 

      session.close(); 
      connection.close(); 

     } catch (JMSException ex) { 
      Logger.getLogger(Foo.class.getName()).log(Level.SEVERE, null, ex); 
     } 
    }  
} 

當我嘗試通過登錄到ActiveMQ管理頁面並檢查隊列來檢查它時,此代碼似乎沒有做任何事情。 (localhost:8161/admin/queues.jsp) 隊列未創建。然後嘗試從管理頁面手動創建隊列,並且即使創建了隊列,也不會將消息發送到隊列。

當我使用命令activemq produceractivemq consumer測試服務器時,會創建隊列並將消息傳遞給隊列並從隊列中讀取。所以我確信服務器沒有問題。

當我運行的代碼是這樣的終端輸出

WARN | Memory Usage for the Broker (1024mb) is more than the maximum available for the JVM: 887 mb - resetting to 70% of maximum available: 621 mb 
INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\Users\Prashan\Desktop\Test\activemq-data\localhost\KahaDB] 
INFO | JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi 
INFO | KahaDB is version 6 
INFO | Recovering from the journal @1:3712 
INFO | Recovery replayed 1 operations from the journal in 0.01 seconds. 
INFO | PListStore:[C:\Users\Prashan\Desktop\Test\activemq-data\localhost\tmp_storage] started 
INFO | Apache ActiveMQ 5.13.2 (localhost, ID:CAPSULE-5179-1461559222267-0:1) is starting 
INFO | Apache ActiveMQ 5.13.2 (localhost, ID:CAPSULE-5179-1461559222267-0:1) started 
INFO | For help or more information please see: http://activemq.apache.org 
WARN | Store limit is 102400 mb (current store usage is 0 mb). The data directory: C:\Users\Prashan\Desktop\Test\activemq-data\localhost\KahaDB only has 6947 mb of usable space. - resetting to maximum available disk space: 6947 mb 
WARN | Temporary Store limit is 51200 mb (current store usage is 0 mb). The data directory: C:\Users\Prashan\Desktop\Test\activemq-data\localhost\tmp_storage only has 6947 mb of usable space. - resetting to maximum available disk space: 6947 mb 
INFO | Connector vm://localhost started 
INFO | Connector vm://localhost stopped 
INFO | Apache ActiveMQ 5.13.2 (localhost, ID:CAPSULE-5179-1461559222267-0:1) is shutting down 
INFO | PListStore:[C:\Users\Prashan\Desktop\Test\activemq-data\localhost\tmp_storage] stopped 
INFO | Stopping async queue tasks 
INFO | Stopping async topic tasks 
INFO | Stopped KahaDB 
INFO | Apache ActiveMQ 5.13.2 (localhost, ID:CAPSULE-5179-1461559222267-0:1) uptime 1.918 seconds 
INFO | Apache ActiveMQ 5.13.2 (localhost, ID:CAPSULE-5179-1461559222267-0:1) is shutdown 

回答

3

你實際上創建嵌入式代理和發送有該消息。您應該通過以下方式連接到本地機器代理:tcp://localhost:61616"而不是vm://...

相關問題