Class FlowProcessingTracker

java.lang.Object
com.mulesoft.extension.mq.internal.FlowProcessingTracker

public class FlowProcessingTracker extends Object
Tracks the number of messages that have been dispatched to the flow but have not yet completed processing. This is used to implement backpressure and prevent the subscriber from fetching more messages than the flow can process (respecting maxConcurrency).

Accounting is strictly per-message so that the counter stays balanced regardless of the fetch batch size:

This fixes the issue where the MQ subscriber would continue to fetch messages even when the flow was at maxConcurrency, causing messages from different FIFO groups to block each other.

Since:
4.0.14
  • Constructor Details

    • FlowProcessingTracker

      public FlowProcessingTracker(int maxInflightMessages, String destinationName)
      Creates a new tracker with the specified maximum inflight messages.
      Parameters:
      maxInflightMessages - the maximum number of messages that can be in-flight (dispatched but not completed). This should match the flow's maxConcurrency setting. Use 1 for FIFO ordering.
      destinationName - the name of the destination for logging purposes
  • Method Details

    • onMessageDispatched

      public void onMessageDispatched()
      Called when an individual message is about to be dispatched to the flow. Increments the inflight counter by one. The matching onMessageCompleted() is called when that message finishes.
    • onMessageCompleted

      public void onMessageCompleted()
      Called when the flow has completed processing a message (either successfully or with an error). This decrements the inflight counter.
    • canAcceptMessage

      public boolean canAcceptMessage()
      Checks if the tracker can accept more messages without exceeding the maxInflightMessages limit.
      Returns:
      true if the current inflight count is below the maximum, false otherwise
    • getInflightCount

      public int getInflightCount()
      Returns the current number of inflight messages.
      Returns:
      the current inflight count
    • getMaxInflightMessages

      public int getMaxInflightMessages()
      Returns the maximum number of inflight messages allowed.
      Returns:
      the maximum inflight messages