Class BatchProcessingException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
io.fluxcapacitor.javaclient.tracking.BatchProcessingException
All Implemented Interfaces:
Serializable

public class BatchProcessingException extends RuntimeException
Exception thrown during message batch processing to intentionally halt tracking after a specific message.

This exception provides a clean way to interrupt processing without treating the batch as failed. When thrown, the tracker stops consuming messages and commits its position up to—but not including—the message at the specified messageIndex.

Semantics

  • The messageIndex refers to the index of the **message that caused the halt** within the current batch.
  • The tracker will commit all messages prior to this index.
  • Remaining messages in the batch will be retried when tracking resumes.

Auto-Indexing

If no index is explicitly provided, the exception will attempt to resolve the current message index automatically via DeserializingMessage.getOptionally(). This makes it convenient to throw from inside a handler or interceptor.

Use Cases

  • Gracefully halting tracking due to domain constraints or environmental factors
  • Aborting a batch without marking it as failed (e.g., for safe reprocessing)
  • Stopping execution when continuation might result in corruption or inconsistency

Example


 @HandleEvent
 public void on(CriticalSystemEvent event) {
     if (systemInUnsafeState()) {
         throw new BatchProcessingException("Unsafe state detected. Halting tracker.");
     }
 }
 

The tracker will commit its position up to the last successfully processed message before the one that triggered the exception.

See Also:
  • Constructor Details

    • BatchProcessingException

      public BatchProcessingException()
      Constructs the exception using the index of the currently handled message, if available.
    • BatchProcessingException

      public BatchProcessingException(String message)
      Constructs the exception with a message and automatically determines the current message index.
    • BatchProcessingException

      public BatchProcessingException(String message, Throwable cause)
      Constructs the exception with a message, cause, and automatically determined message index.
    • BatchProcessingException

      public BatchProcessingException(Long messageIndex)
      Constructs the exception with a specified message index.
    • BatchProcessingException

      public BatchProcessingException(String message, Long messageIndex)
      Constructs the exception with a message and a specified message index.
    • BatchProcessingException

      public BatchProcessingException(String message, Throwable cause, Long messageIndex)
      Constructs the exception with a message, cause, and message index.