【问题标题】:Cannot create ActiveMQ queue or send a message using java无法使用 java 创建 ActiveMQ 队列或发送消息
【发布时间】:2016-08-18 08:05:57
【问题描述】:

我是 ActiveMQ 的新手。我正在使用本地机器上的默认设置在 Windows 上运行 ActiveMQ 服务器。我尝试创建一个简单的队列来测试发送消息。

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 管理页面并检查队列来检查它时,此代码似乎没有做任何事情。 (本地主机: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

【问题讨论】:

    标签: java jms activemq


    【解决方案1】:

    您实际上是在创建一个嵌入式代理,并在那里发送消息。您应该通过tcp://localhost:61616" 而不是vm://... 连接到本地机器代理。

    【讨论】:

      猜你喜欢
      • 2015-05-10
      • 1970-01-01
      • 2015-02-19
      • 2017-09-13
      • 2019-09-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-20
      相关资源
      最近更新 更多