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
/// Derive the KafkaMessage trait for a struct
/// It requires the following attributes:
/// - `key` - the name of the field that will be used as the key
/// - `topic` - the name of the field that will be used as the topic
/// - `headers` - the name of the field that will be used as the headers. Possible values: `CloudEvent` or `None` (default)
/// - `payload` - the name of the field that will be used as the payload
/// - `serde` - the serialization format of the payload. Possible values: `Json`
///
/// Example:
/// ```rust,ignore
/// #[derive(KafkaMessage, Serialize, CloudEvent, Debug, Deserialize)]
/// #[kafka(topic = "test", serde = Json, key = message_id)]
/// struct SomeMessage {
/// pub message_id: i64,
/// }
/// ```
/// Derive the CloudEvent trait for a struct
/// It requires the following attributes:
/// - `content_type` - the content type of the event
/// - `version` - the version of the event
/// - `event_type` - the type of the event
/// - `event_source` - the source of the event
///
/// Implementing `KafkaMessage` is required for this trait to work. The `headers` field of the `KafkaMessage` trait should be set to `CloudEvent`
///
/// Example:
/// ```rust, ignore
/// #[derive(KafkaMessage, Serialize, CloudEvent, Debug, Deserialize)]
/// #[kafka(topic = "test", serde = Json, key = event_id, headers = CloudEvent)]
/// #[cloud_event(
/// content_type = "application/json",
/// version = "1.0",
/// event_type = "com.ene.SomeEvent.v1",
/// event_source = "https://ene-kafka.com/docs/cloudevents/SomeEvent"
/// )]
/// struct SomeEvent {
/// pub event_id: i64,
/// }
/// ```
/// Derive the EventHandler trait for a struct
/// It requires the following attributes:
/// - `event` - A concrete type that implements the `CloudEvent` trait
/// - `handler` - The name of the handler function. This function should be implemented by the struct. It should take a reference to the event it can handle as input.
///
/// The event type should implement `CloudEvent` as well as `DeserializeFrom` is required for this trait to work.
/// Example:
/// ```rust,ignore
/// #[derive(EventHandler)]
/// #[event_handler(event = crate::SomeEvent, handler = handle_some_event)]
/// struct SomeEventHandler;
///
/// impl SomeEventHandler {
/// async fn handle_some_event(&self, event: &crate::SomeEvent) -> anyhow::Result<()> {
/// println!("Handling event: {:?}", event);
/// Ok(())
/// }
/// }
/// ```
/// Derive the DeserializeFrom trait for a struct
/// It relies on the `KafkaMessage` trait and requires the following attributes:
/// - `serde` - the serialization format of the payload. Possible values: `Json`
/// `DeserializeFrom` requires the struct to implement `Deserialize` from the `serde` crate.
///
/// Example:
/// ```rust, ignore
/// #[derive(KafkaMessage, Serialize, CloudEvent, Debug, Deserialize, DeserializeFrom)]
/// #[kafka(topic = "test", serde = Json, key = message_id)]
/// struct SomeMessage {
/// pub message_id: i64,
/// }
/// ```