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
//! Callback system for acknowledgment notifications.
//!
//! This module provides a callback interface for receiving notifications when
//! records or batches are acknowledged by the server.
//!
//! # Examples
//!
//! ```
//! use databricks_zerobus_ingest_sdk::{AckCallback, OffsetId};
//!
//! struct MyCallback;
//!
//! impl AckCallback for MyCallback {
//! fn on_ack(&self, offset_id: OffsetId) {
//! println!("Acknowledged offset: {}", offset_id);
//! }
//!
//! fn on_error(&self, offset_id: OffsetId, error_message: &str) {
//! eprintln!("Error for offset {}: {}", offset_id, error_message);
//! }
//! }
//! ```
use crateOffsetId;
/// Callback trait for receiving acknowledgment notifications.
///
/// Implement this trait to receive callbacks when records/batches are acknowledged
/// by the server or when errors occur.
///
/// # Thread Safety and Performance
///
/// Implementations must be `Send + Sync` as callbacks are invoked from
/// a dedicated background callback handler task.
///
/// **Important**: Callbacks are executed synchronously in a separate callback handler task.
/// Keep implementations lightweight (simple logging, metrics increment, etc.) to avoid
/// accumulating callback backlog. For heavy work like database writes, network calls,
/// or complex processing, consider using channels to send data to dedicated worker tasks.
///
/// # Examples
///
/// ```
/// use databricks_zerobus_ingest_sdk::{AckCallback, OffsetId};
/// use std::sync::atomic::{AtomicI64, Ordering};
///
/// struct CountingCallback {
/// ack_count: AtomicI64,
/// }
///
/// impl AckCallback for CountingCallback {
/// fn on_ack(&self, offset_id: OffsetId) {
/// self.ack_count.fetch_add(1, Ordering::Relaxed);
/// }
///
/// fn on_error(&self, offset_id: OffsetId, error_message: &str) {
/// eprintln!("Error: {}", error_message);
/// }
/// }
/// ```