Skip to content

Workflow step with entity state and event appender #545

Description

@schananas

Why

Today a workflow that needs a guarded decision on event-sourced state has to dispatch a command to a
separate command handler, even when the decision belongs to the process itself. That adds a command
type, a handler and a round trip per decision.

We want an execute step that does what a command handler does, inside the workflow:

  • Better integration with Axon Framework 5. The step uses the same StateManager and
    EventAppender as a command handler, so appended events carry the entity's consistency condition.
  • Less clutter. No extra command type and handler for decisions that only the workflow makes.
  • Decision logic inside the process. The guard and the event live in the step that needs them.
  • No repeated command-send pattern where it is not needed. Commands stay the tool for decisions
    owned by another component.

Proposed API

ctx.execute("enroll", CourseState.class, courseId, (course, appender) -> {
    if (course.isFull()) { return; }
    appender.append(new StudentEnrolled(courseId, studentId));
}).await();

The appender is only available together with the loaded entity. That keeps this separate from
publish, which records workflow progress and is not guarded by any entity.

Implementation

A thin overload over the existing execute(stepName, (processingContext, payload) -> ...). Each execute
step already runs in its own unit of work with a fresh event store transaction, so no engine change
is needed:

public <T> WorkflowStepResult execute(String stepName,
                                      Class<T> entityType,
                                      Object entityId,
                                      BiConsumer<T, EventAppender> decision) {
    return execute(stepName, (processingContext, payload) -> {
        T entity = FutureUtils.joinAndUnwrap(processingContext.component(StateManager.class)
                                                              .loadEntity(entityType, entityId, processingContext));
        decision.accept(entity, EventAppender.forContext(processingContext));
        return Map.of();
    });
}

Activity

  1. added this to the Release 5.5.0 milestone on Sep 28, 2026
  2. changed the title [-]Workflow execute step that loads an event-sourced entity and appends events guarded by it[/-] [+]Workflow step with entity state and event appender[/+] on Sep 28, 2026
  3. added
    Priority 1: MustHighest priority. A release cannot be made if this issue isn’t resolved.
    Type: FeatureUse to signal an issue is completely new to the project.
    on Sep 29, 2026
  4. added theissue type on Sep 29, 2026
  5. removed
    Type: FeatureUse to signal an issue is completely new to the project.
    on Sep 29, 2026
  6. smcvb commented on Nov 17, 2026

    @smcvb
    Contributor

    Relates to #172

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority 1: MustHighest priority. A release cannot be made if this issue isn’t resolved.

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions