Skip to content

Commit dd7e233

Browse files
committed
Review Franz
Modifications: * `KafkaConsumer`: * rename `commitSync(_:)` -> `commit(_:)` * rename `commitAsync(_:)` -> `scheduleCommit(_:)` * `RDKafkaClient`: * rename `commitSync(_:)` -> `commit(_:)` * rename `commitAsync(_:)` -> `scheduleCommit(_:)`
1 parent 0fa9862 commit dd7e233

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

Sources/Kafka/KafkaConsumer.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public final class KafkaConsumer: Sendable, Service {
369369
/// - Parameters:
370370
/// - message: Last received message that shall be marked as read.
371371
/// - Throws: A ``KafkaError`` if committing failed.
372-
public func commitAsync(_ message: KafkaConsumerMessage) throws {
372+
public func triggerCommit(_ message: KafkaConsumerMessage) throws {
373373
let action = self.stateMachine.withLockedValue { $0.commit() }
374374
switch action {
375375
case .throwClosedError:
@@ -379,10 +379,15 @@ public final class KafkaConsumer: Sendable, Service {
379379
throw KafkaError.config(reason: "Committing manually only works if isAutoCommitEnabled set to false")
380380
}
381381

382-
try client.commitAsync(message)
382+
try client.triggerCommit(message)
383383
}
384384
}
385385

386+
@available(*, deprecated, renamed: "commit")
387+
public func commitSync(_ message: KafkaConsumerMessage) async throws {
388+
try await self.commit(message)
389+
}
390+
386391
/// Mark all messages up to the passed message in the topic as read.
387392
/// Awaits until the commit succeeds or an error is encountered.
388393
///
@@ -393,7 +398,7 @@ public final class KafkaConsumer: Sendable, Service {
393398
/// - Parameters:
394399
/// - message: Last received message that shall be marked as read.
395400
/// - Throws: A ``KafkaError`` if committing failed.
396-
public func commitSync(_ message: KafkaConsumerMessage) async throws {
401+
public func commit(_ message: KafkaConsumerMessage) async throws {
397402
let action = self.stateMachine.withLockedValue { $0.commit() }
398403
switch action {
399404
case .throwClosedError:
@@ -403,7 +408,7 @@ public final class KafkaConsumer: Sendable, Service {
403408
throw KafkaError.config(reason: "Committing manually only works if isAutoCommitEnabled set to false")
404409
}
405410

406-
try await client.commitSync(message)
411+
try await client.commit(message)
407412
}
408413
}
409414

Sources/Kafka/RDKafka/RDKafkaClient.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ final class RDKafkaClient: Sendable {
538538
///
539539
/// - Parameter message: Last received message that shall be marked as read.
540540
/// - Throws: A ``KafkaError`` if scheduling the commit failed.
541-
func commitAsync(_ message: KafkaConsumerMessage) throws {
541+
func triggerCommit(_ message: KafkaConsumerMessage) throws {
542542
// The offset committed is always the offset of the next requested message.
543543
// Thus, we increase the offset of the current message by one before committing it.
544544
// See: https://github.com/edenhill/librdkafka/issues/2745#issuecomment-598067945
@@ -566,12 +566,12 @@ final class RDKafkaClient: Sendable {
566566
///
567567
/// - Parameter message: Last received message that shall be marked as read.
568568
/// - Throws: A ``KafkaError`` if the commit failed.
569-
func commitSync(_ message: KafkaConsumerMessage) async throws {
569+
func commit(_ message: KafkaConsumerMessage) async throws {
570570
// Declare captured closure outside of withCheckedContinuation.
571571
// We do that because do an unretained pass of the captured closure to
572572
// librdkafka which means we have to keep a reference to the closure
573573
// ourselves to make sure it does not get deallocated before
574-
// commitSync returns.
574+
// commit returns.
575575
var capturedClosure: CapturedCommitCallback!
576576
try await withCheckedThrowingContinuation { continuation in
577577
capturedClosure = CapturedCommitCallback { result in

Tests/IntegrationTests/KafkaTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ final class KafkaTests: XCTestCase {
214214
}
215215
}
216216

217-
func testProduceAndConsumeWithCommitAsync() async throws {
217+
func testProduceAndConsumeWithTriggerCommit() async throws {
218218
let testMessages = Self.createTestMessages(topic: self.uniqueTestTopic, count: 10)
219219
let (producer, events) = try KafkaProducer.makeProducerWithEvents(configuration: self.producerConfig, logger: .kafkaTest)
220220

@@ -254,7 +254,7 @@ final class KafkaTests: XCTestCase {
254254
var consumedMessages = [KafkaConsumerMessage]()
255255
for try await message in consumer.messages {
256256
consumedMessages.append(message)
257-
try consumer.commitAsync(message)
257+
try consumer.triggerCommit(message)
258258

259259
if consumedMessages.count >= testMessages.count {
260260
break
@@ -272,7 +272,7 @@ final class KafkaTests: XCTestCase {
272272
}
273273
}
274274

275-
func testProduceAndConsumeWithCommitSync() async throws {
275+
func testProduceAndConsumeWithCommit() async throws {
276276
let testMessages = Self.createTestMessages(topic: self.uniqueTestTopic, count: 10)
277277
let (producer, events) = try KafkaProducer.makeProducerWithEvents(configuration: self.producerConfig, logger: .kafkaTest)
278278

@@ -312,7 +312,7 @@ final class KafkaTests: XCTestCase {
312312
var consumedMessages = [KafkaConsumerMessage]()
313313
for try await message in consumer.messages {
314314
consumedMessages.append(message)
315-
try await consumer.commitSync(message)
315+
try await consumer.commit(message)
316316

317317
if consumedMessages.count >= testMessages.count {
318318
break
@@ -381,7 +381,7 @@ final class KafkaTests: XCTestCase {
381381
continue
382382
}
383383
consumedMessages.append(message)
384-
try await consumer.commitSync(message)
384+
try await consumer.commit(message)
385385

386386
if consumedMessages.count >= testMessages.count {
387387
break

0 commit comments

Comments
 (0)