rdkafka_sys/
types.rs

1//! Aliases for types defined in the auto-generated bindings.
2
3use std::convert::TryFrom;
4use std::error::Error;
5use std::ffi::CStr;
6use std::fmt;
7
8use num_enum::IntoPrimitive;
9
10use crate::bindings;
11use crate::helpers;
12
13// TYPES
14
15/// Native rdkafka client.
16pub type RDKafka = bindings::rd_kafka_t;
17
18/// Native rdkafka configuration.
19pub type RDKafkaConf = bindings::rd_kafka_conf_t;
20
21/// Native rdkafka message.
22pub type RDKafkaMessage = bindings::rd_kafka_message_t;
23
24/// Native rdkafka topic.
25pub type RDKafkaTopic = bindings::rd_kafka_topic_t;
26
27/// Native rdkafka topic configuration.
28pub type RDKafkaTopicConf = bindings::rd_kafka_topic_conf_t;
29
30/// Native rdkafka topic partition.
31pub type RDKafkaTopicPartition = bindings::rd_kafka_topic_partition_t;
32
33/// Native rdkafka topic partition list.
34pub type RDKafkaTopicPartitionList = bindings::rd_kafka_topic_partition_list_t;
35
36/// Native rdkafka metadata container.
37pub type RDKafkaMetadata = bindings::rd_kafka_metadata_t;
38
39/// Native rdkafka topic information.
40pub type RDKafkaMetadataTopic = bindings::rd_kafka_metadata_topic_t;
41
42/// Native rdkafka partition information.
43pub type RDKafkaMetadataPartition = bindings::rd_kafka_metadata_partition_t;
44
45/// Native rdkafka broker information.
46pub type RDKafkaMetadataBroker = bindings::rd_kafka_metadata_broker_t;
47
48/// Native rdkafka consumer group metadata.
49pub type RDKafkaConsumerGroupMetadata = bindings::rd_kafka_consumer_group_metadata_t;
50
51/// Native rdkafka state.
52pub type RDKafkaState = bindings::rd_kafka_s;
53
54/// Native rdkafka list of groups.
55pub type RDKafkaGroupList = bindings::rd_kafka_group_list;
56
57/// Native rdkafka group information.
58pub type RDKafkaGroupInfo = bindings::rd_kafka_group_info;
59
60/// Native rdkafka group member information.
61pub type RDKafkaGroupMemberInfo = bindings::rd_kafka_group_member_info;
62
63/// Native rdkafka group member information.
64pub type RDKafkaHeaders = bindings::rd_kafka_headers_t;
65
66/// Native rdkafka queue.
67pub type RDKafkaQueue = bindings::rd_kafka_queue_t;
68
69/// Native rdkafka new topic object.
70pub type RDKafkaNewTopic = bindings::rd_kafka_NewTopic_t;
71
72/// Native rdkafka delete topic object.
73pub type RDKafkaDeleteTopic = bindings::rd_kafka_DeleteTopic_t;
74
75/// Native rdkafka delete group object.
76pub type RDKafkaDeleteGroup = bindings::rd_kafka_DeleteGroup_t;
77
78/// Native rdkafka new partitions object.
79pub type RDKafkaNewPartitions = bindings::rd_kafka_NewPartitions_t;
80
81/// Native rdkafka delete records object.
82pub type RDKafkaDeleteRecords = bindings::rd_kafka_DeleteRecords_t;
83
84/// Native rdkafka config resource.
85pub type RDKafkaConfigResource = bindings::rd_kafka_ConfigResource_t;
86
87/// Native rdkafka event.
88pub type RDKafkaEvent = bindings::rd_kafka_event_t;
89
90/// Native rdkafka admin options.
91pub type RDKafkaAdminOptions = bindings::rd_kafka_AdminOptions_t;
92
93/// Native rdkafka topic result.
94pub type RDKafkaTopicResult = bindings::rd_kafka_topic_result_t;
95
96/// Native rdkafka group result.
97pub type RDKafkaGroupResult = bindings::rd_kafka_group_result_t;
98
99/// Native rdkafka mock cluster.
100pub type RDKafkaMockCluster = bindings::rd_kafka_mock_cluster_t;
101
102// ENUMS
103
104/// Client types.
105pub use bindings::rd_kafka_type_t as RDKafkaType;
106
107/// Configuration result.
108pub use bindings::rd_kafka_conf_res_t as RDKafkaConfRes;
109
110/// Response error.
111pub use bindings::rd_kafka_resp_err_t as RDKafkaRespErr;
112
113/// Admin operation.
114pub use bindings::rd_kafka_admin_op_t as RDKafkaAdminOp;
115
116/// Config resource type.
117pub use bindings::rd_kafka_ResourceType_t as RDKafkaResourceType;
118
119/// Config source.
120pub use bindings::rd_kafka_ConfigSource_t as RDKafkaConfigSource;
121
122// Errors enum
123
124/// Native rdkafka error code.
125#[derive(Debug, Clone, Copy, PartialEq, Eq)]
126#[non_exhaustive]
127pub enum RDKafkaErrorCode {
128    #[doc(hidden)]
129    Begin = -200,
130    /// Received message is incorrect.
131    BadMessage = -199,
132    /// Bad/unknown compression.
133    BadCompression = -198,
134    /// Broker is going away.
135    BrokerDestroy = -197,
136    /// Generic failure.
137    Fail = -196,
138    /// Broker transport failure.
139    BrokerTransportFailure = -195,
140    /// Critical system resource.
141    CriticalSystemResource = -194,
142    /// Failed to resolve broker.
143    Resolve = -193,
144    /// Produced message timed out.
145    MessageTimedOut = -192,
146    /// Reached the end of the topic+partition queue on the broker. Not really an error.
147    PartitionEOF = -191,
148    /// Permanent: Partition does not exist in cluster.
149    UnknownPartition = -190,
150    /// File or filesystem error.
151    FileSystem = -189,
152    /// Permanent: Topic does not exist in cluster.
153    UnknownTopic = -188,
154    /// All broker connections are down.
155    AllBrokersDown = -187,
156    /// Invalid argument, or invalid configuration.
157    InvalidArgument = -186,
158    /// Operation timed out.
159    OperationTimedOut = -185,
160    /// Queue is full.
161    QueueFull = -184,
162    /// ISR count < required.acks.
163    ISRInsufficient = -183,
164    /// Broker node update.
165    NodeUpdate = -182,
166    /// SSL error.
167    SSL = -181,
168    /// Waiting for coordinator to become available.
169    WaitingForCoordinator = -180,
170    /// Unknown client group.
171    UnknownGroup = -179,
172    /// Operation in progress.
173    InProgress = -178,
174    /// Previous operation in progress, wait for it to finish.
175    PreviousInProgress = -177,
176    /// This operation would interfere with an existing subscription.
177    ExistingSubscription = -176,
178    /// Assigned partitions (rebalance_cb).
179    AssignPartitions = -175,
180    /// Revoked partitions (rebalance_cb).
181    RevokePartitions = -174,
182    /// Conflicting use.
183    Conflict = -173,
184    /// Wrong state.
185    State = -172,
186    /// Unknown protocol.
187    UnknownProtocol = -171,
188    /// Not implemented.
189    NotImplemented = -170,
190    /// Authentication failure.
191    Authentication = -169,
192    /// No stored offset.
193    NoOffset = -168,
194    /// Outdated.
195    Outdated = -167,
196    /// Timed out in queue.
197    TimedOutQueue = -166,
198    /// Feature not supported by broker.
199    UnsupportedFeature = -165,
200    /// Awaiting cache update.
201    WaitCache = -164,
202    /// Operation interrupted (e.g., due to yield).
203    Interrupted = -163,
204    /// Key serialization error.
205    KeySerialization = -162,
206    /// Value serialization error.
207    ValueSerialization = -161,
208    /// Key deserialization error.
209    KeyDeserialization = -160,
210    /// Value deserialization error.
211    ValueDeserialization = -159,
212    /// Partial response.
213    Partial = -158,
214    /// Modification attempted on read-only object.
215    ReadOnly = -157,
216    /// No such entry or item not found.
217    NoEnt = -156,
218    /// Read underflow.
219    Underflow = -155,
220    /// Invalid type.
221    InvalidType = -154,
222    /// Retry operation.
223    Retry = -153,
224    /// Purged in queue.
225    PurgeQueue = -152,
226    /// Purged in flight.
227    PurgeInflight = -151,
228    /// Fatal error: see rd_kafka_fatal_error().
229    Fatal = -150,
230    /// Inconsistent state.
231    Inconsistent = -149,
232    /// Gap-less ordering would not be guaranteed if proceeding.
233    GaplessGuarantee = -148,
234    /// Maximum poll interval exceeded.
235    PollExceeded = -147,
236    /// Unknown broker.
237    UnknownBroker = -146,
238    /// Functionality not configured.
239    NotConfigured = -145,
240    /// Instance has been fenced.
241    Fenced = -144,
242    /// Application generated error.
243    Application = -143,
244    /// Assignment lost.
245    AssignmentLost = -142,
246    /// No operation performed.
247    Noop = -141,
248    /// No offset to automatically reset to.
249    AutoOffsetReset = -140,
250    /// Partition log truncation detected
251    LogTruncation = -139,
252    #[doc(hidden)]
253    End = -100,
254    /// Unknown broker error.
255    Unknown = -1,
256    /// Success.
257    NoError = 0,
258    /// Offset out of range.
259    OffsetOutOfRange = 1,
260    /// Invalid message.
261    InvalidMessage = 2,
262    /// Unknown topic or partition.
263    UnknownTopicOrPartition = 3,
264    /// Invalid message size.
265    InvalidMessageSize = 4,
266    /// Leader not available.
267    LeaderNotAvailable = 5,
268    /// Not leader for partition.
269    NotLeaderForPartition = 6,
270    /// Request timed out.
271    RequestTimedOut = 7,
272    /// Broker not available.
273    BrokerNotAvailable = 8,
274    /// Replica not available.
275    ReplicaNotAvailable = 9,
276    /// Message size too large.
277    MessageSizeTooLarge = 10,
278    /// Stale controller epoch code.
279    StaleControllerEpoch = 11,
280    /// Offset metadata string too large.
281    OffsetMetadataTooLarge = 12,
282    /// Broker disconnected before response received.
283    NetworkException = 13,
284    /// Coordinator load in progress.
285    CoordinatorLoadInProgress = 14,
286    /// Coordinator not available.
287    CoordinatorNotAvailable = 15,
288    /// Not coordinator.
289    NotCoordinator = 16,
290    /// Invalid topic.
291    InvalidTopic = 17,
292    /// Message batch larger than configured server segment size.
293    MessageBatchTooLarge = 18,
294    /// Not enough in-sync replicas.
295    NotEnoughReplicas = 19,
296    /// Message(s) written to insufficient number of in-sync replicas.
297    NotEnoughReplicasAfterAppend = 20,
298    /// Invalid required acks value.
299    InvalidRequiredAcks = 21,
300    /// Specified group generation id is not valid.
301    IllegalGeneration = 22,
302    /// Inconsistent group protocol.
303    InconsistentGroupProtocol = 23,
304    /// Invalid group.id.
305    InvalidGroupId = 24,
306    /// Unknown member.
307    UnknownMemberId = 25,
308    /// Invalid session timeout.
309    InvalidSessionTimeout = 26,
310    /// Group rebalance in progress.
311    RebalanceInProgress = 27,
312    /// Commit offset data size is not valid.
313    InvalidCommitOffsetSize = 28,
314    /// Topic authorization failed.
315    TopicAuthorizationFailed = 29,
316    /// Group authorization failed.
317    GroupAuthorizationFailed = 30,
318    /// Cluster authorization failed.
319    ClusterAuthorizationFailed = 31,
320    /// Invalid timestamp.
321    InvalidTimestamp = 32,
322    /// Unsupported SASL mechanism.
323    UnsupportedSASLMechanism = 33,
324    /// Illegal SASL state.
325    IllegalSASLState = 34,
326    /// Unsupported version.
327    UnsupportedVersion = 35,
328    /// Topic already exists.
329    TopicAlreadyExists = 36,
330    /// Invalid number of partitions.
331    InvalidPartitions = 37,
332    /// Invalid replication factor.
333    InvalidReplicationFactor = 38,
334    /// Invalid replica assignment.
335    InvalidReplicaAssignment = 39,
336    /// Invalid config.
337    InvalidConfig = 40,
338    /// Not controller for cluster.
339    NotController = 41,
340    /// Invalid request.
341    InvalidRequest = 42,
342    /// Message format on broker does not support request.
343    UnsupportedForMessageFormat = 43,
344    /// Policy violation.
345    PolicyViolation = 44,
346    /// Broker received an out of order sequence number.
347    OutOfOrderSequenceNumber = 45,
348    /// Broker received a duplicate sequence number.
349    DuplicateSequenceNumber = 46,
350    /// Producer attempted an operation with an old epoch.
351    InvalidProducerEpoch = 47,
352    /// Producer attempted a transactional operation in an invalid state.
353    InvalidTransactionalState = 48,
354    /// Producer attempted to use a producer id which is currently assigned to
355    /// its transactional id.
356    InvalidProducerIdMapping = 49,
357    /// Transaction timeout is larger than the maxi value allowed by the
358    /// broker's max.transaction.timeout.ms.
359    InvalidTransactionTimeout = 50,
360    /// Producer attempted to update a transaction while another concurrent
361    /// operation on the same transaction was ongoing.
362    ConcurrentTransactions = 51,
363    /// Indicates that the transaction coordinator sending a WriteTxnMarker is
364    /// no longer the current coordinator for a given producer.
365    TransactionCoordinatorFenced = 52,
366    /// Transactional Id authorization failed.
367    TransactionalIdAuthorizationFailed = 53,
368    /// Security features are disabled.
369    SecurityDisabled = 54,
370    /// Operation not attempted.
371    OperationNotAttempted = 55,
372    /// Disk error when trying to access log file on the disk.
373    KafkaStorageError = 56,
374    /// The user-specified log directory is not found in the broker config.
375    LogDirNotFound = 57,
376    /// SASL Authentication failed.
377    SaslAuthenticationFailed = 58,
378    /// Unknown Producer Id.
379    UnknownProducerId = 59,
380    /// Partition reassignment is in progress.
381    ReassignmentInProgress = 60,
382    /// Delegation Token feature is not enabled.
383    DelegationTokenAuthDisabled = 61,
384    /// Delegation Token is not found on server.
385    DelegationTokenNotFound = 62,
386    /// Specified Principal is not valid Owner/Renewer.
387    DelegationTokenOwnerMismatch = 63,
388    /// Delegation Token requests are not allowed on this connection.
389    DelegationTokenRequestNotAllowed = 64,
390    /// Delegation Token authorization failed.
391    DelegationTokenAuthorizationFailed = 65,
392    /// Delegation Token is expired.
393    DelegationTokenExpired = 66,
394    /// Supplied principalType is not supported.
395    InvalidPrincipalType = 67,
396    /// The group is not empty.
397    NonEmptyGroup = 68,
398    /// The group id does not exist.
399    GroupIdNotFound = 69,
400    /// The fetch session ID was not found.
401    FetchSessionIdNotFound = 70,
402    /// The fetch session epoch is invalid.
403    InvalidFetchSessionEpoch = 71,
404    /// No matching listener.
405    ListenerNotFound = 72,
406    /// Topic deletion is disabled.
407    TopicDeletionDisabled = 73,
408    /// Leader epoch is older than broker epoch.
409    FencedLeaderEpoch = 74,
410    /// Leader epoch is newer than broker epoch.
411    UnknownLeaderEpoch = 75,
412    /// Unsupported compression type.
413    UnsupportedCompressionType = 76,
414    /// Broker epoch has changed.
415    StaleBrokerEpoch = 77,
416    /// Leader high watermark is not caught up.
417    OffsetNotAvailable = 78,
418    /// Group member needs a valid member ID.
419    MemberIdRequired = 79,
420    /// Preferred leader was not available.
421    PreferredLeaderNotAvailable = 80,
422    /// Consumer group has reached maximum size.
423    GroupMaxSizeReached = 81,
424    /// Static consumer fenced by other consumer with same group.instance.id.
425    FencedInstanceId = 82,
426    /// Eligible partition leaders are not available.
427    EligibleLeadersNotAvailable = 83,
428    /// Leader election not needed for topic partition.
429    ElectionNotNeeded = 84,
430    /// No partition reassignment is in progress.
431    NoReassignmentInProgress = 85,
432    /// Deleting offsets of a topic while the consumer group is subscribed to
433    /// it.
434    GroupSubscribedToTopic = 86,
435    /// Broker failed to validate record.
436    InvalidRecord = 87,
437    /// There are unstable offsets that need to be cleared.
438    UnstableOffsetCommit = 88,
439    /// Throttling quota has been exceeded.
440    ThrottlingQuotaExceeded = 89,
441    /// There is a newer producer with the same transactional ID which fences
442    /// the current one.
443    ProducerFenced = 90,
444    /// Request illegally referred to resource that does not exist.
445    ResourceNotFound = 91,
446    /// Request illegally referred to the same resource twice.
447    DuplicateResource = 92,
448    /// Requested credential would not meet criteria for acceptability.
449    UnacceptableCredential = 93,
450    /// Either the sender or recipient of a voter-only request is not one of the
451    /// expected voters.
452    InconsistentVoterSet = 94,
453    /// Invalid update version.
454    InvalidUpdateVersion = 95,
455    /// Unable to update finalized features due to server error.
456    FeatureUpdateFailed = 96,
457    /// Request principal deserialization failed during forwarding.
458    PrincipalDeserializationFailure = 97,
459    #[doc(hidden)]
460    EndAll,
461}
462
463impl From<RDKafkaRespErr> for RDKafkaErrorCode {
464    fn from(err: RDKafkaRespErr) -> RDKafkaErrorCode {
465        helpers::rd_kafka_resp_err_t_to_rdkafka_error(err)
466    }
467}
468
469impl fmt::Display for RDKafkaErrorCode {
470    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
471        let description = match RDKafkaRespErr::try_from(*self as i32) {
472            Ok(err) => {
473                let cstr = unsafe { bindings::rd_kafka_err2str(err) };
474                unsafe { CStr::from_ptr(cstr) }
475                    .to_string_lossy()
476                    .into_owned()
477            }
478            Err(_) => "Unknown error".to_owned(),
479        };
480
481        write!(f, "{:?} ({})", self, description)
482    }
483}
484
485impl Error for RDKafkaErrorCode {}
486
487/// Native rdkafka ApiKeys / protocol requests
488#[derive(Debug, Clone, Copy, PartialEq, Eq, IntoPrimitive)]
489#[repr(i16)]
490#[non_exhaustive]
491pub enum RDKafkaApiKey {
492    Produce = 0,
493    Fetch = 1,
494    ListOffsets = 2,
495    Metadata = 3,
496    LeaderAndIsr = 4,
497    StopReplica = 5,
498    UpdateMetadata = 6,
499    ControlledShutdown = 7,
500    OffsetCommit = 8,
501    OffsetFetch = 9,
502    FindCoordinator = 10,
503    JoinGroup = 11,
504    Heartbeat = 12,
505    LeaveGroup = 13,
506    SyncGroup = 14,
507    DescribeGroups = 15,
508    ListGroups = 16,
509    SaslHandshake = 17,
510    ApiVersion = 18,
511    CreateTopics = 19,
512    DeleteTopics = 20,
513    DeleteRecords = 21,
514    InitProducerId = 22,
515    OffsetForLeaderEpoch = 23,
516    AddPartitionsToTxn = 24,
517    AddOffsetsToTxn = 25,
518    EndTxn = 26,
519    WriteTxnMarkers = 27,
520    TxnOffsetCommit = 28,
521    DescribeAcls = 29,
522    CreateAcls = 30,
523    DeleteAcls = 31,
524    DescribeConfigs = 32,
525    AlterConfigs = 33,
526    AlterReplicaLogDirs = 34,
527    DescribeLogDirs = 35,
528    SaslAuthenticate = 36,
529    CreatePartitions = 37,
530    CreateDelegationToken = 38,
531    RenewDelegationToken = 39,
532    ExpireDelegationToken = 40,
533    DescribeDelegationToken = 41,
534    DeleteGroups = 42,
535    ElectLeaders = 43,
536    IncrementalAlterConfigs = 44,
537    AlterPartitionReassignments = 45,
538    ListPartitionReassignments = 46,
539    OffsetDelete = 47,
540    DescribeClientQuotas = 48,
541    AlterClientQuotas = 49,
542    DescribeUserScramCredentials = 50,
543    AlterUserScramCredentials = 51,
544    Vote = 52,
545    BeginQuorumEpoch = 53,
546    EndQuorumEpoch = 54,
547    DescribeQuorum = 55,
548    AlterIsr = 56,
549    UpdateFeatures = 57,
550    Envelope = 58,
551}
552
553#[cfg(test)]
554mod tests {
555    use super::*;
556
557    #[test]
558    fn test_display_error() {
559        let error: RDKafkaErrorCode = RDKafkaRespErr::RD_KAFKA_RESP_ERR__PARTITION_EOF.into();
560        assert_eq!(
561            "PartitionEOF (Broker: No more messages)",
562            format!("{}", error)
563        );
564        assert_eq!("PartitionEOF", format!("{:?}", error));
565    }
566}