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