Class FlowProcessingTracker
java.lang.Object
com.mulesoft.extension.mq.internal.FlowProcessingTracker
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:
- Call
canAcceptMessage()before fetching new messages (non-mutating capacity check) - Call
onMessageDispatched()for each individual message as it is dispatched to the flow (+1) - Call
onMessageCompleted()when the flow completes processing that message, in @OnSuccess or @OnError (-1)
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 Summary
ConstructorsConstructorDescriptionFlowProcessingTracker(int maxInflightMessages, String destinationName) Creates a new tracker with the specified maximum inflight messages. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if the tracker can accept more messages without exceeding the maxInflightMessages limit.intReturns the current number of inflight messages.intReturns the maximum number of inflight messages allowed.voidCalled when the flow has completed processing a message (either successfully or with an error).voidCalled when an individual message is about to be dispatched to the flow.
-
Constructor Details
-
FlowProcessingTracker
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 matchingonMessageCompleted()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
-