Are you an LLM? You can read better optimized documentation at /guide/extensions/webflux.md for this page in Markdown format
WebFlux
The WebFlux extension provides support for Spring WebFlux, depending on the routing specifications generated by the wow-openapi module, automatically registering command route handlers to implement declarative REST APIs.
Installation
kotlin
implementation("me.ahoo.wow:wow-webflux")groovy
implementation 'me.ahoo.wow:wow-webflux'xml
<dependency>
<groupId>me.ahoo.wow</groupId>
<artifactId>wow-webflux</artifactId>
<version>${wow.version}</version>
</dependency>Automatic Route Registration
The WebFlux extension automatically generates REST API endpoints for all commands:
Route Patterns
Supports multiple route patterns:
Aggregate Route Pattern
kotlin
@AggregateRoot
@AggregateRoute(owner = AggregateRoute.Owner.AGGREGATE_ID)
class Cart(private val state: CartState)
// Generated route: POST /cart/{cartId}/add_cart_itemOwner Route Pattern
kotlin
@AggregateRoot
@AggregateRoute(owner = AggregateRoute.Owner.ALWAYS)
class Order(private val state: OrderState)
// Generated route: POST /order/owner/{ownerId}/create_orderHTTP Method Mapping
| Command Annotation | HTTP Method | Default Path |
|---|---|---|
@CreateAggregate | POST | /{resource} |
@CommandRoute(method = POST) | POST | /{resource}/{command} |
@CommandRoute(method = PUT) | PUT | /{resource}/{command} |
@CommandRoute(method = DELETE) | DELETE | /{resource}/{command} |
Wait Strategy Integration
The WebFlux extension supports specifying wait strategies through HTTP headers:
http
POST /cart/123/add_cart_item
Content-Type: application/json
Command-Wait-Stage: PROCESSED
Command-Wait-Timeout: 30000
{
"productId": "product-456",
"quantity": 2
}Supported Wait Strategies
SENT: Command sentPROCESSED: Command processedPROJECTED: Event projectedSNAPSHOT: Snapshot created
Error Handling
The WebFlux extension provides unified error response format:
json
{
"errorCode": "VALIDATION_ERROR",
"errorMsg": "Product not found",
"requestId": "req-123"
}OpenAPI Integration
Automatically generates OpenAPI documentation:
yaml
paths:
/cart/{cartId}/add_cart_item:
post:
summary: "Add item to cart"
parameters:
- name: cartId
in: path
required: true
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/AddCartItem'Performance Optimization
Reactive Processing
All endpoints use reactive programming:
kotlin
@RestController
class CustomController(
private val commandGateway: CommandGateway
) {
@PostMapping("/custom/{id}")
fun customCommand(@PathVariable id: String): Mono<CommandResult> {
return commandGateway.sendAndWait(
CustomCommand(id = id),
WaitStrategy.PROCESSED
)
}
}Connection Pool Configuration
yaml
spring:
codec:
max-in-memory-size: 10MB
webflux:
session:
timeout: 30mMonitoring and Debugging
Request Logging
yaml
logging:
level:
me.ahoo.wow.webflux: DEBUGPerformance Metrics
Automatically collects the following metrics:
- Request latency and throughput
- Error rate statistics
- Wait strategy usage
Best Practices
- Use Wait Strategies: Choose appropriate wait strategies based on business requirements
- Error Handling: Implement global exception handlers
- Security: Enable authentication and authorization checks
- Monitoring: Configure appropriate log levels and metrics collection
- Performance: Configure connection pools and timeouts appropriately