1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//! microsvc — Convention-based microservice command handler framework.
//!
//! Build microservices by registering command and event handlers on typed
//! `Routes<D>` bundles, then adding those bundles to a deployment-level
//! `Service`. Each handler receives a `Context<D>` with access to the input
//! payload, session variables, and its route dependencies.
//!
//! ## Quick Start
//!
//! Dispatch is **async** — `dispatch`, `handle`, and the commit path all return
//! futures and are awaited.
//!
//! ```ignore
//! use std::sync::Arc;
//! use distributed::{microsvc, HashMapRepository};
//! use serde_json::json;
//!
//! let routes = microsvc::Routes::new()
//! .with_repo(HashMapRepository::new().queued().aggregate::<Order>())
//! .command("order.create")
//! .handle(|ctx| {
//! let input = ctx.input::<CreateOrderInput>();
//! async move { Ok(json!({ "id": input?.id })) }
//! });
//! let service = Arc::new(microsvc::Service::new().routes(routes));
//!
//! // Direct dispatch (async)
//! let result = service
//! .dispatch("order.create", json!({ "id": "o1" }), microsvc::Session::new())
//! .await?;
//!
//! // HTTP transport (requires "http" feature)
//! // microsvc::serve(service, "0.0.0.0:3000").await?;
//! ```
//!
//! ## Handler Convention
//!
//! Each handler file follows this convention. `handle` is **async**:
//!
//! ```ignore
//! // src/handlers/order_create.rs
//!
//! pub const COMMAND: &str = "order.create";
//!
//! pub fn guard(ctx: µsvc::Context<Repo>) -> bool {
//! ctx.has_fields(&["id", "product_id"])
//! }
//!
//! pub async fn handle(ctx: µsvc::Context<'_, Repo>) -> Result<Value, microsvc::HandlerError> {
//! let input = ctx.input::<CreateOrderInput>()?;
//! let mut order = Order::default();
//! order.create(input.id)?;
//! ctx.repo().commit(&mut order).await?;
//! Ok(json!({ "id": order.entity().id() }))
//! }
//! ```
pub use crate;
pub use Context;
pub use ;
pub use HandlerError;
pub use ;
pub use ;
pub use Session;
/// Maximum accepted HTTP request body size for the microsvc ingresses, in bytes
/// (1 MiB).
///
/// Pins axum's implicit 2 MiB default to an explicit, smaller ceiling shared by
/// the command [`router`] and the CloudEvents [`cloud_events_router`]: both
/// buffer the whole body into memory, so an unbounded body is a
/// memory-amplification vector. Raise it deliberately if a deployment needs
/// larger payloads.
pub const MAX_HTTP_BODY_BYTES: usize = 1024 * 1024;
// HTTP transport (requires "http" feature)
pub use ;
// Knative / CloudEvents HTTP ingress (Service-coupled; the bus keeps only the
// produce/manifest helpers). Requires the "http" feature.
pub use cloud_events_router;
// gRPC transport (requires "grpc" feature)
pub use ;
/// Register handler modules with a route bundle using the convention pattern.
///
/// Each handler entry must be prefixed with `command`, `event`, or `events`.
///
/// Command handler modules must export:
/// - `COMMAND: &str` — the command name
/// - `guard(ctx) -> bool` — input validation
/// - `handle(ctx) -> Result<Value, HandlerError>` — the handler
///
/// Event handler modules must export:
/// - `EVENT: &str` or `EVENTS: &[&str]` — event names
/// - `guard(ctx) -> bool` — input validation
/// - `handle(ctx) -> Result<Value, HandlerError>` — the handler
///
/// # Example
/// ```ignore
/// let routes = distributed::routes!(
/// microsvc::Routes::new().with_repo(repo),
/// command handlers::counter_create,
/// command handlers::counter_increment,
/// event handlers::counter_rebuilt,
/// events handlers::counter_projection,
/// );
/// let service = microsvc::Service::new().routes(routes);
/// ```
;
=> ;
=> ;
=> ;
}