Class MessageTracker


  • @Beta
    public final class MessageTracker
    extends Object
    MessageTracker is a diagnostic utility class to be used for figuring out why a certain message which was expected to arrive in a given time interval does not arrive. It attempts to keep track of all the messages that received between the arrival of two instances of the same message and the amount of time it took to process each of those messages.
    Usage of the API is as follows,
    
          // Track the Foo class, Here we expect to see a message of type Foo come in every 10 millis
         MessageTracker tracker = new MessageTracker(Foo.class, 10);
    
         // Begin the tracking process. If this is not called then calling received and done on the resultant Context
         // will do nothing
         tracker.begin();
    
         .....
    
         try (MessageTracker.Context context = tracker.received(message)) {
    
             if (context.error().isPresent()){
                 LOG.error("{}", context.error().get());
             }
    
             // Some custom processing
             process(message);
         }
    
     

    This class is NOT thread-safe.

    • Constructor Detail

      • MessageTracker

        public MessageTracker​(Class<?> expectedMessageClass,
                              long expectedArrivalIntervalInMillis)
        Constructs an instance.
        Parameters:
        expectedMessageClass - the class of the message to track
        expectedArrivalIntervalInMillis - the expected arrival interval between two instances of the expected message