Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法接收嵌入的ActiveMQ统计信息_Java_Junit_Activemq - Fatal编程技术网

Java 无法接收嵌入的ActiveMQ统计信息

Java 无法接收嵌入的ActiveMQ统计信息,java,junit,activemq,Java,Junit,Activemq,我正试图通过JUnit测试从嵌入式ActiveMQ获取主题的订阅统计信息。我能够订阅该主题,向该主题发送消息,并能够在我的侦听器/订阅者中接收该消息 但是,当我尝试从ActiveMQ获取统计信息时,使用者接收超时。如果我没有添加“receiveTimeout”,消费者就会无限期地等待消息。以下是我的统计代码: ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhos

我正试图通过JUnit测试从嵌入式ActiveMQ获取主题的订阅统计信息。我能够订阅该主题,向该主题发送消息,并能够在我的侦听器/订阅者中接收该消息

但是,当我尝试从ActiveMQ获取统计信息时,使用者接收超时。如果我没有添加“receiveTimeout”,消费者就会无限期地等待消息。以下是我的统计代码:

    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
    connectionFactory.setStatsEnabled(true);

    Connection connection = connectionFactory.createConnection();
    connection.setClientID(format("ActiveMqStatistics-%s", System.nanoTime()));
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue replyTo = session.createTemporaryQueue();
    MessageConsumer consumer = session.createConsumer(replyTo);

    String queueName = "ActiveMQ.Statistics.Subscription";
    Queue testQueue = session.createQueue(queueName);
    MessageProducer producer = session.createProducer(testQueue);
    Message msg = session.createMessage();
    msg.setJMSReplyTo(replyTo);
    producer.send(msg);

    System.out.println("Statistics request sent. Waiting to receive reply...");

    long receiveTimeout = 5000L;
    MapMessage reply = (MapMessage) consumer.receive(receiveTimeout);
    assertNotNull(reply);

    for (Enumeration e = reply.getMapNames();e.hasMoreElements();) {
        String name = e.nextElement().toString();
        System.out.println(name + "=" + reply.getObject(name));
    }

    connection.close();
我得到断言失败,因为“reply”为空


有什么想法吗?

为了让它发挥作用,您需要创建一个安装了统计代理插件的代理实例,它不是现成的

在XML配置中,可以按如下方式启用它:

<broker ...>
  <plugins>
    <statisticsBrokerPlugin/>
  </plugins>
</broker>

我也有同样的问题,我找到了解决办法。我正在使用XML配置activeMQ嵌入式代理,我可以添加statisticsBrokerPlugin,如下所示

<!-- lets create an embedded ActiveMQ Broker -->
    <amq:broker useJmx="false" persistent="false" enableStatistics="true" brokerName="xxx-test-broker" brokerId="xxx-test">
        <amq:transportConnectors>
            <amq:transportConnector uri="tcp://localhost:0" />
        </amq:transportConnectors>
        **<amq:plugins>
            <amq:statisticsBrokerPlugin/>
        </amq:plugins>**
    </amq:broker>

**
**
因此,我的activeMQ连接URL将是vm://localhost


我认为这对某些人很有用。

您的代理中是否安装了StatisticBrokerPlugin?蒂姆:不,我使用的是虚拟嵌入式activemq,即代理URL为“vm://localhost?broker.persistent=false”。根据文档(),这应该得到支持。
<!-- lets create an embedded ActiveMQ Broker -->
    <amq:broker useJmx="false" persistent="false" enableStatistics="true" brokerName="xxx-test-broker" brokerId="xxx-test">
        <amq:transportConnectors>
            <amq:transportConnector uri="tcp://localhost:0" />
        </amq:transportConnectors>
        **<amq:plugins>
            <amq:statisticsBrokerPlugin/>
        </amq:plugins>**
    </amq:broker>