ActiveMQ(Java) - 检查连接处于活动状态的时间(即消费者或生产者)

时间:2017-06-26 20:31:25

标签: java apache connection activemq producer-consumer

我目前正在使用Apache ActiveMQ作为JMS解决方案在客户端之间来回发送各种消息。我想检查特定客户(即消费者或生产者)的正常运行时间,但到目前为止我还没有找到办法。我已经检查了咨询消息和StatisticsPlugin,以获取有关如何执行此操作的任何信息,但没有找到任何帮助。

我可以尝试在我的Consumer和Producer类中嵌入一个时钟,并创建一个特殊的咨询目的地,用于发送消息以从这些类中检索时间;然而,这似乎不切实际。

有没有人知道更好的解决方案或在ActiveMQ中执行此操作的方法?

1 个答案:

答案 0 :(得分:0)

为什么咨询不是解决方案? 您可以通过将主题 ActiveMQ.Advisory.Connection 中的消息路由到队列来使用它,以便在需要时计算并计算正常运行时间。

将此代码段添加到activemq.xml

...
    </broker>

    <!-- configure the camel activemq component to use the current broker -->

    <bean  id="ActiveMQVMConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="vm://localhost?create=false&amp;waitForStart=10000"/>
        <property name="userName" value="${activemq.username}"/>
        <property name="password" value="${activemq.password}"/>
    </bean>
    <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent" >
        <property name="connectionFactory" ref="ActiveMQVMConnectionFactory"/>
    </bean>

    <camelContext id="camel" trace="false" xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="activemq:topic:ActiveMQ.Advisory.Connection" />
            <to uri="activemq:queue:Advisory"/>
        </route> 
    </camelContext>
相关问题