diff --git a/Sources/SwiftKafka/KafkaTransactionalProducer.swift b/Sources/SwiftKafka/KafkaTransactionalProducer.swift index 61139ba2..c16e2874 100644 --- a/Sources/SwiftKafka/KafkaTransactionalProducer.swift +++ b/Sources/SwiftKafka/KafkaTransactionalProducer.swift @@ -14,7 +14,7 @@ public final class KafkaTransactionalProducer: Service, Sendable { /// /// This creates a producer without listening for events. /// - /// - Parameter config: The ``KafkaProducerConfiguration`` for configuring the ``KafkaProducer``. + /// - Parameter config: The ``KafkaTransactionalProducerConfiguration`` for configuring the ``KafkaProducer``. /// - Parameter topicConfig: The ``KafkaTopicConfiguration`` used for newly created topics. /// - Parameter logger: A logger. /// - Returns: The newly created ``KafkaProducer``. @@ -57,15 +57,18 @@ public final class KafkaTransactionalProducer: Service, Sendable { return (transactionalProducer, events) } - // - public func withTransaction(_ body: @Sendable (KafkaTransaction) async throws -> Void) async throws { + /// Begins Kafka transaction, provides it to given closure + /// Commits transaction unless closure throws + /// - Parameters: + /// - function: revieve KafkaTransaction and use fills it with produced messages and offsets + public func withTransaction(_ function: @Sendable (KafkaTransaction) async throws -> Void) async throws { let transaction = try KafkaTransaction( client: try producer.client(), producer: self.producer ) do { // need to think here a little bit how to abort transaction - try await body(transaction) + try await function(transaction) try await transaction.commit() } catch { // FIXME: maybe catch AbortTransaction? do { diff --git a/Tests/IntegrationTests/Utilities.swift b/Tests/IntegrationTests/Utilities.swift index e6bd9290..1dc91d8b 100644 --- a/Tests/IntegrationTests/Utilities.swift +++ b/Tests/IntegrationTests/Utilities.swift @@ -20,7 +20,7 @@ import Logging extension Logger { static var kafkaTest: Logger { var logger = Logger(label: "kafka.test") - logger.logLevel = .debug + logger.logLevel = .debug // TODO: revert return logger } }