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
//! Kafka producer and consumers for [Autumn](https://autumn-web.app) apps.
//!
//! # Quick start
//!
//! ```rust,no_run
//! use autumn_plugin_kafka::{Consumer, HandlerError, KafkaPlugin, KafkaProducer, Message, Record};
//! use autumn_web::prelude::*;
//!
//! #[derive(serde::Serialize, serde::Deserialize)]
//! struct Order {
//! id: u64,
//! }
//!
//! #[post("/orders/{id}")]
//! async fn create(producer: KafkaProducer, Path(id): Path<u64>) -> AutumnResult<&'static str> {
//! producer
//! .send(Record::json("orders", &Order { id })?.with_key(id.to_string()))
//! .await?;
//! Ok("queued")
//! }
//!
//! async fn on_order(msg: Message, _state: AppState) -> Result<(), HandlerError> {
//! let order: Order = msg.json()?;
//! tracing::info!(id = order.id, "order received");
//! Ok(())
//! }
//!
//! #[autumn_web::main]
//! async fn main() {
//! autumn_web::app()
//! .plugin(
//! KafkaPlugin::new().consumer(
//! Consumer::new("orders", ["orders"])
//! .group_id("billing")
//! .handler(on_order)
//! .dead_letter_topic("orders.dlq"),
//! ),
//! )
//! .routes(routes![create])
//! .run()
//! .await;
//! }
//! ```
//!
//! # Parts
//!
//! | Part | Function |
//! |---|---|
//! | [`KafkaPlugin`] | Installs all parts. Reads `[kafka]` at startup. |
//! | [`KafkaConfig`] | The `[kafka]` config section. |
//! | [`KafkaProducer`] | Sends records. It is a handler argument. |
//! | [`Consumer`] | A consumer with an async handler. |
//! | [`MemoryBroker`] | An in-memory broker for tests. |
//! | [`RdKafkaBackend`] | The default client, `librdkafka`. |
//!
//! The plugin also adds the `kafka` health indicator and `kafka_*` metrics
//! to `/actuator/prometheus`.
//!
//! # Delivery
//!
//! Consumers are at-least-once. The plugin commits an offset only after the
//! handler completes, or after the dead-letter send completes.
//! A handler can get the same message again. Make sure that this is safe.
//!
//! # Example
//!
//! `examples/orders.rs` uses all parts. CI runs its self-check.
pub use ;
pub use ;
pub use ;
pub use KafkaError;
/// The future type of the backend traits.
pub use BoxFuture;
pub use MemoryBroker;
pub use ;
pub use ;
pub use KafkaProducer;
pub use RdKafkaBackend;