0

I am currently using Apache ActiveMQ as a JMS solution to send various messages back and forth between clients. I would like to check the uptime for specific clients (i.e. 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.

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; however, this seems impractical.

Does anyone know of a better solution or a way to do this in ActiveMQ?

J Dack.
  • 23
  • 4

1 Answers1

0

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.

add this snippet to your 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>
Hassen Bennour
  • 3,885
  • 2
  • 12
  • 20
  • Sending messages to a queue from the advisory topic isn't the problem I'm having, it's being able to get the uptime. How would I do this? Is there some kind of function I missed or should I use another method? Edit: I should also mention that I am not using xml, only Java. – J Dack. Jun 28 '17 at 17:13
  • Every time a connection starts or stops a message is sent to the topic ActiveMQ.Advisory.Connection with informations. because it is a topic if your client who calculates uptime is not connected he will loose the messages and for this I proposed to you to send them to a queue to treat them later. so if you calculate the difference between the time of the startup message and the stop message you have the uptime no ?? You use an embedded ActiveMQ ? You can create the Camel route programmatically or embeds a java listener in place – Hassen Bennour Jun 28 '17 at 19:50
  • That is a good idea, but the problem with it is I want to calculate the uptime even when my "advisory" program is offline. Users would be able to connect and send messages. Any amoutn of time later, I can check the connection uptime without having to leave the program open to receive the initial connection information message. I think I'll stick with the clock idea though, since I found out how to make it work accurately and without having to open up extra connections to manage advisory messages as well as whatever topics or queues the consumer and producers are already subscribed to. – J Dack. Jun 28 '17 at 20:08
  • The problem with the clock or calculation on the client side is that when the broker goes down or networks failures your uptime will be corrupted by the retries or failover... depends on the accuracy you need but if your clients are embedded in the same JVM than ActiveMQ this can be a good solution – Hassen Bennour Jun 28 '17 at 20:31