简体   繁体   English

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

[英]ActiveMQ (Java) - Checking the amount of time a connection has been active (i.e. Consumer or Producer)

I am currently using Apache ActiveMQ as a JMS solution to send various messages back and forth between clients. 我目前正在使用Apache ActiveMQ作为JMS解决方案来在客户端之间来回发送各种消息。 I would like to check the uptime for specific clients (ie Consumer or Producers), but I have not found a way to do this so far. 我想检查特定客户(例如,消费者或生产者)的正常运行时间,但是到目前为止,我还没有找到一种方法。 I have checked the Advisory messages and StatisticsPlugin for any information on how to do this but have found nothing helpful. 我已经查看了咨询消息和StatisticsPlugin,以获取有关如何执行此操作的任何信息,但没有发现任何帮助。

I could try embedding a clock in my Consumer and Producer classes and creating a special advisory destination for sending messages to retrieve the time from those classes; 我可以尝试将时钟嵌入到Consumer和Producer类中,并创建一个特殊的咨询目标来发送消息以从这些类中检索时间。 however, this seems impractical. 但是,这似乎不切实际。

Does anyone know of a better solution or a way to do this in ActiveMQ? 有谁知道在ActiveMQ中有更好的解决方案或方法吗?

why advisory is not the solution ?? 为什么咨询不是解决方案? you can use it like this by routing messages from topic ActiveMQ.Advisory.Connection to a queue to process them when you want and calculate the uptime. 您可以通过将主题ActiveMQ.Advisory.Connection中的消息路由到队列以在需要时处理它们并计算正常运行时间,来像这样使用它。

add this snippet to your activemq.xml 将此片段添加到您的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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM