Expand description
§kanin
A framework for AMQP built on top of lapin.
kanin makes it easy to create RPC microservices using protobuf in Rust with minimal boilerplate.
§Example
// EchoRequest and EchoResponse are protobuf messages as generated by prost_build: https://docs.rs/prost-build/latest/prost_build/index.html
async fn echo(Msg(request): Msg<EchoRequest>, State(num): State<u8>) -> EchoResponse {
assert_eq!(42, num);
EchoResponse::success(request.value)
}
#[derive(AppState)]
struct MyState {
num: u8
}
#[tokio::main]
async fn main() -> kanin::Result<()> {
App::new(MyState { num: 42 })
.handler("my_routing_key", echo)
.run("amqp://localhost")
.await
}
§Help, why is my handler rejected by kanin?
There can be several reasons.
Firstly, ensure that all parameters implement Extract
.
Especially for Msg
, ensure the version of the prost
crate used for the inner type is the same as the prost type used by kanin
.
You can remove parameters one by one until the function is accepted to find out which parameter is the problem.
You can see if you have multiple prost
versions by checking your Cargo.lock
file.
Secondly, ensure that the response type implements Respond
. Once again, Protobuf messages automatically implement this but your prost
version must match.
If you’re sure these things are handled, try to replace the body of the handler with todo!()
.
If this causes the handler to work, then it’s likely that the future your async function is creating is not Send
.
Your future must be Send
. It is probably not Send
because you’re holding on to a type that is not Send
across an await point.
For instance, holding a std::sync::MutexGuard
across an await point will cause your future to not be Send
.
Re-exports§
pub use app::App;
pub use error::Error;
pub use error::HandlerError;
pub use extract::Extract;
pub use handler::Handler;
pub use handler_config::HandlerConfig;
pub use request::Request;
pub use response::Respond;
pub use lapin;
Modules§
- Module for the App struct and surrounding utilities.
- Kanin-specific error types.
- Interface for types that can extract themselves from requests.
- Handlers are functions whose arguments can be constructed from the app or the incoming AMQP message.
- Handler configuration.
- AMQP requests.
- AMQP responses.
Structs§
- A TCP connection to the AMQP server.
Type Aliases§
- Convenience type for a result with
kanin
’s error.
Derive Macros§
- Derives
From<&S>
for all the fields in theS
struct. - Derives the
kanin::error::FromError
trait for a type. This only works under specific circumstances.