-
Notifications
You must be signed in to change notification settings - Fork 23
Add Order Fulfillment Workflow and Workflow Saga demo apps #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
schananas
wants to merge
5
commits into
main
Choose a base branch
from
feat/workflow-demo-apps
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| # Order Fulfillment Workflow | ||
|
|
||
| Sample project showing how to model an order fulfillment process using the | ||
| **Axoniq Workflow Engine**. The workflow is written as plain imperative Java — | ||
| the engine handles event sourcing, crash recovery, and audit trails. | ||
|
|
||
| ```java | ||
| @Workflow(idProperty = "orderId", startOnEvent = "io.axoniq.demo.orderfulfillment.api.OrderPlaced") | ||
| public void execute(SimpleWorkflowContext ctx) { | ||
| // Register the wait FIRST, so the workflow is subscribed before any payment-confirmation | ||
| // event has a chance to land. | ||
| var paymentConfirmation = ctx.waitForEvent("awaitPayment", PaymentConfirmed.class, | ||
| associate(payloadProperty("orderId"), equalsTo(orderId)), Duration.ofMinutes(15)); | ||
|
|
||
| var reserved = ctx.awaitExecute("reserveStock", payload, Boolean.class, inventory::reserveStock); | ||
| if (!reserved) { | ||
| paymentConfirmation.cancel("Stock unavailable"); | ||
| ctx.fail(new RuntimeException("Stock unavailable")); | ||
| return; | ||
| } | ||
| ctx.awaitExecute("initiatePayment", payload, payment::initiatePayment, | ||
| Duration.ofSeconds(30), | ||
| baseName("InitiatingPaymentForCustomer").namespace("io.axoniq.demo.orderfulfillment.api")); | ||
|
|
||
| paymentConfirmation.await(); | ||
|
|
||
| // The Completed event of `shipOrder` (`ShipOrderCompleted`, in the api namespace) is what the | ||
| // projection subscribes to — no eventGateway.publish anywhere inside the workflow. | ||
| var shipResult = ctx.awaitExecute("shipOrder", payload, shipping::shipOrder, | ||
| Duration.ofSeconds(30), namespace("io.axoniq.demo.orderfulfillment.api")); | ||
| ctx.awaitExecute("notifyCustomer", Boolean.class, () -> { notifications.sendConfirmation(email); return true; }); | ||
| } | ||
| ``` | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Java 21+ | ||
| - Maven 3.9+ | ||
| - Docker (for Axon Server) | ||
| - The Axon Workflow Engine (`io.axoniq.framework.workflow:*:1.0.0-SNAPSHOT`) installed in the local Maven repository | ||
|
|
||
| If the workflow engine isn't published yet, build it locally first: | ||
|
|
||
| ```bash | ||
| git clone git@github.com:AxonIQ/extension-workflow.git | ||
| cd extension-workflow | ||
| mvn clean install -DskipTests | ||
| ``` | ||
|
|
||
| ## Running the application | ||
|
|
||
| ```bash | ||
| docker compose up -d | ||
| mvn spring-boot:run | ||
| ``` | ||
|
|
||
| The application starts on port **9090**. | ||
|
|
||
| ### REST endpoints | ||
|
|
||
| | Method | Path | Description | | ||
| |--------|-------------------------------|---------------------------------------------| | ||
| | POST | `/orders?customerId=&email=&amount=` | Place a new order. Returns the order id. | | ||
| | POST | `/orders/{orderId}/payment` | Confirm payment and resume the workflow. | | ||
| | GET | `/orders/{orderId}` | Read the order's projected status. | | ||
|
|
||
| ### Quick demo | ||
|
|
||
| ```bash | ||
| # 1. place an order | ||
| ORDER=$(curl -s -X POST 'http://localhost:9090/orders?customerId=alice&email=alice@example.com&amount=99.95') | ||
|
|
||
| # 2. confirm payment | ||
| curl -X POST "http://localhost:9090/orders/$ORDER/payment" | ||
|
|
||
| # 3. observe the projected status | ||
| curl "http://localhost:9090/orders/$ORDER" | ||
| ``` | ||
|
|
||
| ## Integration test | ||
|
|
||
| ```bash | ||
| mvn verify | ||
| ``` | ||
|
|
||
| `OrderFulfillmentIT` boots the application against a real Axon Server (started | ||
| via Testcontainers), places an order, confirms payment, and asserts that the | ||
| projection reaches the `SHIPPED` state. | ||
|
|
||
| ## What this sample demonstrates | ||
|
|
||
| * `@Workflow` with `idProperty` and `startOnEvent` | ||
| * `awaitExecute` with payload and typed return value | ||
| * `awaitExecute` with timeout and event-name customization (`baseName(...)`) | ||
| * `awaitEvent` correlated to the workflow instance via `associate(payloadProperty(...), equalsTo(...))` | ||
| * `ctx.fail(...)` to terminate a workflow with an error | ||
| * A standard `@EventHandler` projection consuming events emitted by the workflow's actions | ||
|
|
||
| ## Cleanup | ||
|
|
||
| ```bash | ||
| docker compose down -v | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| services: | ||
| axon-server: | ||
| image: docker.axoniq.io/axoniq/axonserver:2026.0.0 | ||
| container_name: order-fulfillment-axon-server | ||
| ports: | ||
| - "8024:8024" | ||
| - "8124:8124" | ||
| environment: | ||
| axoniq.axonserver.standalone-dcb: true | ||
| axoniq_axonserver_hostname: axon-server | ||
| axoniq_axonserver_devmode_enabled: true | ||
| volumes: | ||
| - data:/axonserver/data | ||
| - events:/axonserver/events | ||
|
|
||
| volumes: | ||
| data: | ||
| driver: local | ||
| events: | ||
| driver: local |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,187 @@ | ||||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||||||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||||
| <modelVersion>4.0.0</modelVersion> | ||||||
|
|
||||||
| <groupId>io.axoniq.demo</groupId> | ||||||
| <artifactId>order-fulfillment-workflow</artifactId> | ||||||
| <version>0.0.1-SNAPSHOT</version> | ||||||
| <name>Order Fulfillment Workflow</name> | ||||||
| <description>Sample showing how to model an Order Fulfillment process with the Axon Workflow Engine.</description> | ||||||
|
|
||||||
| <properties> | ||||||
| <java.version>21</java.version> | ||||||
| <maven.compiler.source>21</maven.compiler.source> | ||||||
| <maven.compiler.target>21</maven.compiler.target> | ||||||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||||||
|
|
||||||
| <axon.version>5.1.0</axon.version> | ||||||
| <axoniq-framework.version>5.1.0</axoniq-framework.version> | ||||||
| <axon-workflow.version>1.0.0-SNAPSHOT</axon-workflow.version> | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| <spring-boot.version>4.0.6</spring-boot.version> | ||||||
| <testcontainers.version>2.0.5</testcontainers.version> | ||||||
| </properties> | ||||||
|
|
||||||
| <dependencyManagement> | ||||||
| <dependencies> | ||||||
| <dependency> | ||||||
| <groupId>org.springframework.boot</groupId> | ||||||
| <artifactId>spring-boot-dependencies</artifactId> | ||||||
| <version>${spring-boot.version}</version> | ||||||
| <type>pom</type> | ||||||
| <scope>import</scope> | ||||||
| </dependency> | ||||||
| <dependency> | ||||||
| <groupId>org.axonframework</groupId> | ||||||
| <artifactId>axon-framework-bom</artifactId> | ||||||
| <version>${axon.version}</version> | ||||||
| <type>pom</type> | ||||||
| <scope>import</scope> | ||||||
| </dependency> | ||||||
| <dependency> | ||||||
| <groupId>io.axoniq.framework</groupId> | ||||||
| <artifactId>axoniq-framework-bom</artifactId> | ||||||
| <version>${axoniq-framework.version}</version> | ||||||
| <type>pom</type> | ||||||
| <scope>import</scope> | ||||||
| </dependency> | ||||||
| <dependency> | ||||||
| <groupId>org.testcontainers</groupId> | ||||||
| <artifactId>testcontainers-bom</artifactId> | ||||||
| <version>${testcontainers.version}</version> | ||||||
| <type>pom</type> | ||||||
| <scope>import</scope> | ||||||
| </dependency> | ||||||
| </dependencies> | ||||||
| </dependencyManagement> | ||||||
|
|
||||||
| <dependencies> | ||||||
| <!-- Axon Workflow Engine: auto-configures @Workflow beans through Spring Boot. --> | ||||||
| <dependency> | ||||||
| <groupId>io.axoniq.framework.workflow</groupId> | ||||||
| <artifactId>axon-workflow-spring-boot</artifactId> | ||||||
| <version>${axon-workflow.version}</version> | ||||||
| </dependency> | ||||||
|
|
||||||
| <!-- Axon Framework Spring Boot integration --> | ||||||
| <dependency> | ||||||
| <groupId>org.axonframework.extensions.spring</groupId> | ||||||
| <artifactId>axon-spring-boot-starter</artifactId> | ||||||
| </dependency> | ||||||
| <dependency> | ||||||
| <groupId>io.axoniq.framework</groupId> | ||||||
| <artifactId>axon-server-connector</artifactId> | ||||||
| </dependency> | ||||||
|
|
||||||
| <!-- Web --> | ||||||
| <dependency> | ||||||
| <groupId>org.springframework.boot</groupId> | ||||||
| <artifactId>spring-boot-starter-web</artifactId> | ||||||
| </dependency> | ||||||
| <dependency> | ||||||
| <groupId>com.fasterxml.jackson.core</groupId> | ||||||
| <artifactId>jackson-databind</artifactId> | ||||||
| </dependency> | ||||||
|
|
||||||
| <!-- Test --> | ||||||
| <dependency> | ||||||
| <groupId>io.axoniq.framework.workflow</groupId> | ||||||
| <artifactId>axon-workflow-test</artifactId> | ||||||
| <version>${axon-workflow.version}</version> | ||||||
| <scope>test</scope> | ||||||
| </dependency> | ||||||
| <dependency> | ||||||
| <groupId>org.springframework.boot</groupId> | ||||||
| <artifactId>spring-boot-starter-test</artifactId> | ||||||
| <scope>test</scope> | ||||||
| </dependency> | ||||||
| <dependency> | ||||||
| <groupId>org.springframework.boot</groupId> | ||||||
| <artifactId>spring-boot-resttestclient</artifactId> | ||||||
| <scope>test</scope> | ||||||
| </dependency> | ||||||
| <dependency> | ||||||
| <groupId>org.springframework.boot</groupId> | ||||||
| <artifactId>spring-boot-restclient</artifactId> | ||||||
| <scope>test</scope> | ||||||
| </dependency> | ||||||
| <dependency> | ||||||
| <groupId>io.axoniq.framework</groupId> | ||||||
| <artifactId>axoniq-testcontainer</artifactId> | ||||||
| <scope>test</scope> | ||||||
| </dependency> | ||||||
| <dependency> | ||||||
| <groupId>org.testcontainers</groupId> | ||||||
| <artifactId>testcontainers</artifactId> | ||||||
| <scope>test</scope> | ||||||
| </dependency> | ||||||
| <dependency> | ||||||
| <groupId>org.testcontainers</groupId> | ||||||
| <artifactId>testcontainers-junit-jupiter</artifactId> | ||||||
| <scope>test</scope> | ||||||
| </dependency> | ||||||
| <dependency> | ||||||
| <groupId>org.awaitility</groupId> | ||||||
| <artifactId>awaitility</artifactId> | ||||||
| <scope>test</scope> | ||||||
| </dependency> | ||||||
| <dependency> | ||||||
| <groupId>org.assertj</groupId> | ||||||
| <artifactId>assertj-core</artifactId> | ||||||
| <scope>test</scope> | ||||||
| </dependency> | ||||||
| </dependencies> | ||||||
|
|
||||||
| <build> | ||||||
| <plugins> | ||||||
| <plugin> | ||||||
| <groupId>org.apache.maven.plugins</groupId> | ||||||
| <artifactId>maven-compiler-plugin</artifactId> | ||||||
| <version>3.14.1</version> | ||||||
| <configuration> | ||||||
| <source>${java.version}</source> | ||||||
| <target>${java.version}</target> | ||||||
| <parameters>true</parameters> | ||||||
| </configuration> | ||||||
| </plugin> | ||||||
| <plugin> | ||||||
| <groupId>org.springframework.boot</groupId> | ||||||
| <artifactId>spring-boot-maven-plugin</artifactId> | ||||||
| <version>${spring-boot.version}</version> | ||||||
| </plugin> | ||||||
| <plugin> | ||||||
| <groupId>org.apache.maven.plugins</groupId> | ||||||
| <artifactId>maven-surefire-plugin</artifactId> | ||||||
| <version>3.5.4</version> | ||||||
| </plugin> | ||||||
| <plugin> | ||||||
| <groupId>org.apache.maven.plugins</groupId> | ||||||
| <artifactId>maven-failsafe-plugin</artifactId> | ||||||
| <version>3.5.4</version> | ||||||
| <executions> | ||||||
| <execution> | ||||||
| <goals> | ||||||
| <goal>integration-test</goal> | ||||||
| <goal>verify</goal> | ||||||
| </goals> | ||||||
| </execution> | ||||||
| </executions> | ||||||
| </plugin> | ||||||
| </plugins> | ||||||
| </build> | ||||||
|
|
||||||
| <repositories> | ||||||
| <repository> | ||||||
| <id>central-portal-snapshots</id> | ||||||
| <name>Central Portal Snapshots</name> | ||||||
| <url>https://central.sonatype.com/repository/maven-snapshots/</url> | ||||||
| <releases> | ||||||
| <enabled>false</enabled> | ||||||
| </releases> | ||||||
| <snapshots> | ||||||
| <enabled>true</enabled> | ||||||
| </snapshots> | ||||||
| </repository> | ||||||
| </repositories> | ||||||
| </project> | ||||||
12 changes: 12 additions & 0 deletions
12
...t-workflow/src/main/java/io/axoniq/demo/orderfulfillment/OrderFulfillmentApplication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package io.axoniq.demo.orderfulfillment; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| @SpringBootApplication | ||
| public class OrderFulfillmentApplication { | ||
|
|
||
| public static void main(String[] args) { | ||
| SpringApplication.run(OrderFulfillmentApplication.class, args); | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
...rc/main/java/io/axoniq/demo/orderfulfillment/api/InitiatingPaymentForCustomerStarted.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package io.axoniq.demo.orderfulfillment.api; | ||
|
|
||
| /** | ||
| * Emitted automatically by the workflow engine when the {@code initiatePayment} step starts. | ||
| * Used as a synchronisation point: by the time this event is in the store, the workflow has | ||
| * already registered its {@code awaitPayment} wait (the wait is registered at the very top | ||
| * of the workflow, before any {@code awaitExecute} step runs). | ||
| */ | ||
| public record InitiatingPaymentForCustomerStarted(String orderId) { | ||
| } |
10 changes: 10 additions & 0 deletions
10
...ulfillment-workflow/src/main/java/io/axoniq/demo/orderfulfillment/api/OrderDelivered.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package io.axoniq.demo.orderfulfillment.api; | ||
|
|
||
| import org.axonframework.messaging.eventhandling.annotation.Event; | ||
|
|
||
| @Event | ||
| public record OrderDelivered( | ||
| String orderId, | ||
| String trackingNumber | ||
| ) { | ||
| } |
10 changes: 10 additions & 0 deletions
10
...r-fulfillment-workflow/src/main/java/io/axoniq/demo/orderfulfillment/api/OrderFailed.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package io.axoniq.demo.orderfulfillment.api; | ||
|
|
||
| import org.axonframework.messaging.eventhandling.annotation.Event; | ||
|
|
||
| @Event | ||
| public record OrderFailed( | ||
| String orderId, | ||
| String reason | ||
| ) { | ||
| } |
19 changes: 19 additions & 0 deletions
19
...r-fulfillment-workflow/src/main/java/io/axoniq/demo/orderfulfillment/api/OrderPlaced.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package io.axoniq.demo.orderfulfillment.api; | ||
|
|
||
| import org.axonframework.messaging.eventhandling.annotation.Event; | ||
|
|
||
| @Event | ||
| public record OrderPlaced( | ||
| String orderId, | ||
| String customerId, | ||
| String email, | ||
| double amount, | ||
| String originCity, | ||
| double originLat, | ||
| double originLng, | ||
| String destinationCity, | ||
| double destinationLat, | ||
| double destinationLng, | ||
| String scenario | ||
| ) { | ||
| } |
10 changes: 10 additions & 0 deletions
10
...fillment-workflow/src/main/java/io/axoniq/demo/orderfulfillment/api/PaymentConfirmed.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package io.axoniq.demo.orderfulfillment.api; | ||
|
|
||
| import org.axonframework.messaging.eventhandling.annotation.Event; | ||
|
|
||
| @Event | ||
| public record PaymentConfirmed( | ||
| String orderId, | ||
| String transactionId | ||
| ) { | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.