@@ -259,42 +259,10 @@ public final class KafkaProducer: Service, Sendable {
259
259
return KafkaProducerMessageID ( rawValue: newMessageID)
260
260
}
261
261
}
262
-
263
- func initTransactions( timeout: Duration = . seconds( 5 ) ) async throws {
264
- guard config. transactionalId != nil else {
265
- throw KafkaError . config (
266
- reason: " Could not initialize transactions because transactionalId is not set in config " )
267
- }
268
- let client = try self . stateMachine. withLockedValue { try $0. initTransactions ( ) }
269
- try await client. initTransactions ( timeout: timeout)
270
- }
271
-
272
- func beginTransaction( ) throws {
273
- let client = try self . stateMachine. withLockedValue { try $0. transactionsClient ( ) }
274
- try client. beginTransaction ( )
275
- }
276
-
277
- func send(
278
- offsets: RDKafkaTopicPartitionList ,
279
- forConsumer consumer: KafkaConsumer ,
280
- timeout: Duration = . kafkaUntilEndOfTransactionTimeout,
281
- attempts: UInt64 = . max
282
- ) async throws {
283
- let client = try self . stateMachine. withLockedValue { try $0. transactionsClient ( ) }
284
- let consumerClient = try consumer. client ( )
285
- try await consumerClient. withKafkaHandlePointer {
286
- try await client. send ( attempts: attempts, offsets: offsets, forConsumerKafkaHandle: $0, timeout: timeout)
287
- }
288
- }
289
-
290
- func abortTransaction(
291
- timeout: Duration = . kafkaUntilEndOfTransactionTimeout,
292
- attempts: UInt64 ) async throws {
293
- let client = try self . stateMachine. withLockedValue { try $0. transactionsClient ( ) }
294
- try await client. abortTransaction ( attempts: attempts, timeout: timeout)
262
+
263
+ func client( ) throws -> RDKafkaClient {
264
+ try self . stateMachine. withLockedValue { try $0. client ( ) }
295
265
}
296
-
297
-
298
266
}
299
267
300
268
// MARK: - KafkaProducer + StateMachine
@@ -322,18 +290,6 @@ extension KafkaProducer {
322
290
source: Producer . Source ? ,
323
291
topicHandles: RDKafkaTopicHandles
324
292
)
325
- /// The ``KafkaProducer`` has started and is ready to use, transactions were initialized.
326
- ///
327
- /// - Parameter messageIDCounter:Used to incrementally assign unique IDs to messages.
328
- /// - Parameter client: Client used for handling the connection to the Kafka cluster.
329
- /// - Parameter source: ``NIOAsyncSequenceProducer/Source`` used for yielding new elements.
330
- /// - Parameter topicHandles: Class containing all topic names with their respective `rd_kafka_topic_t` pointer.
331
- case startedWithTransactions(
332
- client: RDKafkaClient ,
333
- messageIDCounter: UInt ,
334
- source: Producer . Source ? ,
335
- topicHandles: RDKafkaTopicHandles
336
- )
337
293
/// Producer is still running but the event asynchronous sequence was terminated.
338
294
/// All incoming events will be dropped.
339
295
///
@@ -401,7 +357,7 @@ extension KafkaProducer {
401
357
switch self . state {
402
358
case . uninitialized:
403
359
fatalError ( " \( #function) invoked while still in state \( self . state) " )
404
- case . started( let client, _, let source, _) , . startedWithTransactions ( let client , _ , let source , _ ) :
360
+ case . started( let client, _, let source, _) :
405
361
return . pollAndYield( client: client, source: source)
406
362
case . consumptionStopped( let client) :
407
363
return . pollWithoutYield( client: client)
@@ -444,19 +400,6 @@ extension KafkaProducer {
444
400
newMessageID: newMessageID,
445
401
topicHandles: topicHandles
446
402
)
447
- case . startedWithTransactions( let client, let messageIDCounter, let source, let topicHandles) :
448
- let newMessageID = messageIDCounter + 1
449
- self . state = . startedWithTransactions(
450
- client: client,
451
- messageIDCounter: newMessageID,
452
- source: source,
453
- topicHandles: topicHandles
454
- )
455
- return . send(
456
- client: client,
457
- newMessageID: newMessageID,
458
- topicHandles: topicHandles
459
- )
460
403
case . consumptionStopped:
461
404
throw KafkaError . connectionClosed ( reason: " Sequence consuming events was abruptly terminated, producer closed " )
462
405
case . finishing:
@@ -482,7 +425,7 @@ extension KafkaProducer {
482
425
fatalError ( " \( #function) invoked while still in state \( self . state) " )
483
426
case . consumptionStopped:
484
427
fatalError ( " messageSequenceTerminated() must not be invoked more than once " )
485
- case . started( let client, _, let source, _) , . startedWithTransactions ( let client , _ , let source , _ ) :
428
+ case . started( let client, _, let source, _) :
486
429
self . state = . consumptionStopped( client: client)
487
430
return . finishSource( source: source)
488
431
case . finishing( let client, let source) :
@@ -502,34 +445,28 @@ extension KafkaProducer {
502
445
switch self . state {
503
446
case . uninitialized:
504
447
fatalError ( " \( #function) invoked while still in state \( self . state) " )
505
- case . started( let client, _, let source, _) , . startedWithTransactions ( let client , _ , let source , _ ) :
448
+ case . started( let client, _, let source, _) :
506
449
self . state = . finishing( client: client, source: source)
507
450
case . consumptionStopped( let client) :
508
451
self . state = . finishing( client: client, source: nil )
509
452
case . finishing, . finished:
510
453
break
511
454
}
512
455
}
513
-
514
- mutating func initTransactions ( ) throws -> RDKafkaClient {
456
+
457
+ func client ( ) throws -> RDKafkaClient {
515
458
switch self . state {
516
459
case . uninitialized:
517
460
fatalError ( " \( #function) invoked while still in state \( self . state) " )
518
- case . started( let client, let messageIDCounter, let source, let topicHandles) :
519
- self . state = . startedWithTransactions( client: client, messageIDCounter: messageIDCounter, source: source, topicHandles: topicHandles)
461
+ case . started( let client, _, _, _) :
520
462
return client
521
- case . startedWithTransactions:
522
- throw KafkaError . config ( reason: " Transactions were already initialized " )
523
- case . consumptionStopped, . finishing, . finished:
524
- throw KafkaError . connectionClosed ( reason: " Producer is stopping or finished " )
525
- }
526
- }
527
-
528
- func transactionsClient( ) throws -> RDKafkaClient {
529
- guard case let . startedWithTransactions( client, _, _, _) = self . state else {
530
- throw KafkaError . transactionAborted ( reason: " Transactions were not initialized or producer is being stopped " )
463
+ case . consumptionStopped( let client) :
464
+ return client
465
+ case . finishing( let client, _) :
466
+ return client
467
+ case . finished:
468
+ throw KafkaError . connectionClosed ( reason: " Client stopped " )
531
469
}
532
- return client
533
470
}
534
471
}
535
472
}
0 commit comments