Interface MessageScheduler
- All Known Implementing Classes:
DefaultMessageScheduler
public interface MessageScheduler
Interface for scheduling deferred or periodic execution of messages in the Flux Capacitor platform.
The MessageScheduler
provides functionality for:
- Deferring arbitrary payloads (to be handled via
HandleSchedule
). - Scheduling commands (to be handled via standard
@HandleCommand
handlers). - Recurring execution using cron expressions via the
Periodic
annotation.
Scheduling semantics
When using schedule(...)
:
- Scheduled payloads are delivered to handler methods annotated with
@HandleSchedule
. - Used when the intention is to invoke scheduling-specific logic or workflows.
When using scheduleCommand(...)
:
- The scheduled payload will be dispatched as a command at the configured deadline.
- Handlers annotated with
@HandleCommand
will receive the message, just like normal commands. - This is useful for scenarios where both immediate and delayed invocation use the same handler logic.
Schedule identity
All schedules are identified by a scheduleId
. By default, one is generated unless explicitly passed.
If a schedule with the same ID already exists:
- It is replaced by default.
- Use
ifAbsent = true
to ensure the schedule is only created if it does not already exist.
Typical usage
This interface underpins the static helpers inFluxCapacitor
, such as:
FluxCapacitor.schedule(myPayload, Duration.ofMinutes(5)); FluxCapacitor.scheduleCommand(myCommand, Instant.now().plusSeconds(10));
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
cancelSchedule
(String scheduleId) Cancel a previously scheduled message or command by ID.getSchedule
(String scheduleId) Look up an existing schedule.default void
Schedule a message object (typically of typeSchedule
) for execution, using theGuarantee.SENT
guarantee.default void
Schedule a message, optionally skipping if already present, using theGuarantee.SENT
guarantee.Schedule the givenSchedule
object, optionally skipping if already present, using the specified guarantee.default void
Schedule a message with payload and metadata using a delay, using theGuarantee.SENT
guarantee.default void
Schedule a message with payload and metadata, using theGuarantee.SENT
guarantee.default void
Schedule a message with a custom ID using a delay.default void
Schedule a message with the given ID and deadline, using theGuarantee.SENT
guarantee.default String
Schedule a message using a delay from the current time, using theGuarantee.SENT
guarantee.default String
Schedule a message to be triggered at the given deadline, using theGuarantee.SENT
guarantee.default void
scheduleCommand
(Schedule message) Schedule a command message using the given scheduling settings, using theGuarantee.SENT
guarantee.default void
scheduleCommand
(Schedule message, boolean ifAbsent) Schedule a command using the given scheduling settings if no other with same ID exists, using theGuarantee.SENT
guarantee.scheduleCommand
(Schedule message, boolean ifAbsent, Guarantee guarantee) Schedule a command using the given scheduling settings, using the providedGuarantee
.default void
scheduleCommand
(Object schedulePayload, Metadata metadata, String scheduleId, Duration delay) Schedule a command with metadata and delay, using theGuarantee.SENT
guarantee.default void
scheduleCommand
(Object schedulePayload, Metadata metadata, String scheduleId, Instant deadline) Schedule a command message with attached metadata, using theGuarantee.SENT
guarantee.default void
scheduleCommand
(Object schedule, String scheduleId, Duration delay) Schedule a command with the given ID and delay, using theGuarantee.SENT
guarantee.default void
scheduleCommand
(Object schedule, String scheduleId, Instant deadline) Schedule a command using a specific deadline, using theGuarantee.SENT
guarantee.default String
scheduleCommand
(Object schedule, Duration delay) Schedule a command to execute after given delay, using theGuarantee.SENT
guarantee.default String
scheduleCommand
(Object schedule, Instant deadline) Schedule a command message for future execution.default String
schedulePeriodic
(Object value) Schedule a periodic message using the@Periodic
annotation on its class, using theGuarantee.SENT
guarantee.default String
schedulePeriodic
(Object value, String scheduleId) Schedule a periodic message using the given ID and the@Periodic
annotation, using theGuarantee.SENT
guarantee.
-
Method Details
-
schedulePeriodic
Schedule a periodic message using the@Periodic
annotation on its class, using theGuarantee.SENT
guarantee.- Parameters:
value
- the payload to schedule periodically- Returns:
- the schedule ID
- Throws:
IllegalArgumentException
- if the annotation is missing or misconfigured
-
schedulePeriodic
Schedule a periodic message using the given ID and the@Periodic
annotation, using theGuarantee.SENT
guarantee.- Parameters:
value
- the payload to schedule periodicallyscheduleId
- a custom ID or null to generate one- Returns:
- the effective schedule ID
-
schedule
Schedule a message to be triggered at the given deadline, using theGuarantee.SENT
guarantee.- Parameters:
schedule
- the message to scheduledeadline
- the absolute time to trigger the message- Returns:
- the generated schedule ID
-
schedule
Schedule a message using a delay from the current time, using theGuarantee.SENT
guarantee.- Parameters:
schedule
- the message to scheduledelay
- delay duration until the schedule triggers- Returns:
- the generated schedule ID
-
schedule
Schedule a message with a custom ID using a delay.- Parameters:
schedule
- the message to schedulescheduleId
- the unique ID of the scheduledelay
- the delay until triggering
-
schedule
default void schedule(Object schedulePayload, Metadata metadata, String scheduleId, Instant deadline) Schedule a message with payload and metadata, using theGuarantee.SENT
guarantee.- Parameters:
schedulePayload
- the message payloadmetadata
- metadata to attachscheduleId
- the unique schedule IDdeadline
- the deadline for triggering the schedule
-
schedule
Schedule a message with payload and metadata using a delay, using theGuarantee.SENT
guarantee.- Parameters:
schedulePayload
- the message payloadmetadata
- metadata to attachscheduleId
- the schedule IDdelay
- delay from now until triggering
-
schedule
Schedule a message with the given ID and deadline, using theGuarantee.SENT
guarantee.- Parameters:
schedule
- the object to schedulescheduleId
- unique schedule IDdeadline
- the absolute time at which the schedule should trigger
-
schedule
Schedule a message object (typically of typeSchedule
) for execution, using theGuarantee.SENT
guarantee.- Parameters:
message
- the message to schedule
-
schedule
Schedule a message, optionally skipping if already present, using theGuarantee.SENT
guarantee.- Parameters:
message
- the schedule messageifAbsent
- whether to skip scheduling if an existing schedule is present
-
schedule
Schedule the givenSchedule
object, optionally skipping if already present, using the specified guarantee.- Parameters:
message
- the schedule messageifAbsent
- only schedule if not already scheduledguarantee
- the delivery guarantee to use- Returns:
- a CompletableFuture completing when the message is successfully scheduled
-
scheduleCommand
Schedule a command message for future execution. This is similar toschedule(java.lang.Object, java.time.Instant)
but ensures the message is dispatched as a command, using theGuarantee.SENT
guarantee.- Parameters:
schedule
- the command to scheduledeadline
- the deadline for execution- Returns:
- the generated schedule ID
-
scheduleCommand
Schedule a command to execute after given delay, using theGuarantee.SENT
guarantee.- Parameters:
schedule
- the command to scheduledelay
- delay until execution- Returns:
- the schedule ID
-
scheduleCommand
Schedule a command with the given ID and delay, using theGuarantee.SENT
guarantee.- Parameters:
schedule
- the command to schedulescheduleId
- schedule IDdelay
- delay until execution
-
scheduleCommand
default void scheduleCommand(Object schedulePayload, Metadata metadata, String scheduleId, Instant deadline) Schedule a command message with attached metadata, using theGuarantee.SENT
guarantee.- Parameters:
schedulePayload
- payload of the commandmetadata
- metadata to attachscheduleId
- schedule IDdeadline
- execution deadline
-
scheduleCommand
default void scheduleCommand(Object schedulePayload, Metadata metadata, String scheduleId, Duration delay) Schedule a command with metadata and delay, using theGuarantee.SENT
guarantee.- Parameters:
schedulePayload
- payload to schedulemetadata
- metadata to attachscheduleId
- schedule IDdelay
- delay duration
-
scheduleCommand
Schedule a command using a specific deadline, using theGuarantee.SENT
guarantee.- Parameters:
schedule
- the command object or messagescheduleId
- the schedule IDdeadline
- deadline for triggering the schedule
-
scheduleCommand
Schedule a command message using the given scheduling settings, using theGuarantee.SENT
guarantee.- Parameters:
message
- the command message
-
scheduleCommand
Schedule a command using the given scheduling settings if no other with same ID exists, using theGuarantee.SENT
guarantee.- Parameters:
message
- the command scheduleifAbsent
- whether to skip if already scheduled
-
scheduleCommand
Schedule a command using the given scheduling settings, using the providedGuarantee
.- Parameters:
message
- the command scheduleifAbsent
- skip if existing schedule is presentguarantee
- the delivery guarantee to apply- Returns:
- a future indicating when the command is scheduled
-
cancelSchedule
Cancel a previously scheduled message or command by ID.- Parameters:
scheduleId
- the ID of the schedule to cancel
-
getSchedule
Look up an existing schedule.- Parameters:
scheduleId
- the ID of the schedule- Returns:
- the schedule if found
-