feat: Add event subscriptions and CLI sender#158
Merged
Conversation
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one. |
Adds a programmatic event-consumer API and a generic CLI sender to
make local testing of services and events possible without the
RabbitMQ management UI or hand-edited example files.
Library
-------
* New `EventHandler` type alias mirroring `RpcHandler`:
Arc<dyn Fn(RpcContext, Value) -> BoxFuture<GirolleResult<()>>
+ Send + Sync>
* `RpcService::subscribe(source_service, event_type, handler)` —
registers an async event handler. A service may now consist of
RPC methods, event subscriptions, or both. The empty-service
panic now triggers only when both are empty.
* New `queue::create_event_consumer_channel` declares the source's
`{source}.events` topic exchange (idempotent, durable), declares
a durable consumer queue named
`evt-<source>-<event_type>--<service>`, binds with the routing
key, and applies `prefetch_count`. The consumer can come up
before any publisher.
* `rpc_service` startup spins up one consumer per subscription;
each delivery is decoded as JSON, wrapped in an `RpcContext`
(with the inbound headers stamped on the RpcCaller), and handed
to the handler. Acks always fire, even if the handler errors —
events are best-effort.
* The shared `Semaphore` is now `Arc<Semaphore>` so RPC and event
consumers share the same `max_workers` budget.
Examples
--------
* `cli_sender` — a generic RPC sender:
cargo run --example cli_sender -- <service> <method> [arg ...]
Args are parsed as JSON when possible, falling back to plain
strings, so numbers/booleans/objects can be sent directly.
* `event_observer` — subscribes to `users.user_created` and prints
each event payload as it arrives.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
dff6b72 to
0cd94da
Compare
Refresh the README, the front-page lib.rs doc that powers the docs.rs page, and the Zola getting-started chapters to reflect the async handler rework that landed across the recent feature PRs. * Replace the outdated `&[Value]`-sync hand-rolled handler snippet with the current `Arc<Fn(RpcContext, Payload) -> BoxFuture<...>>` form. * Document `RpcContext` and the two capability handles it carries: `ctx.rpc.call(service, method, payload)` for in-service RPC and `ctx.events.dispatch(source, event_type, &payload)` for events. * Document `RpcService::subscribe(source, event_type, handler)` with example code; note that subscriptions and `register(...)` calls can coexist, and either alone is valid. * Drop the stale "no proxy / no pubsub" caveats that describe the pre-async era, and mark the corresponding checklist items. * Index every runnable example (proxy_service, event_emitter, event_observer, cli_sender) in a single table in the README and quick-start chapter. * Three new doctests on the front-page lib.rs example all compile. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Copilot <copilot@github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Tooling + lib changes that make the new RPC and events features testable locally without the RabbitMQ management UI.
Library
EventHandlertype alias mirroringRpcHandler: `Arc<dyn Fn(RpcContext, Value) -> BoxFuture<GirolleResult<()>> + Send + Sync>`.Examples
`cargo run --example cli_sender -- [arg ...]`
Args are parsed as JSON when possible, falling back to plain strings, so numbers / booleans / objects can be passed directly.
Relationship to other PRs
Local test plan
Checks
Known limitations (deferred)
🤖 Generated with Claude Code