Skip to content

Commit 4470f69

Browse files
KafkaProducerConfig: add allow.auto.create.topics option (#55)
* KafkaProducerConfig: add allow.auto.create.topics Motivation: * the `allow.auto.create.topics` was missing in our `KafkaProducerConfig` * Note: the default value for `allow.auto.create.topics` is `true` for `KafkaProducerConfig` and `false` for `KafkaConsumerConfig` (this is adapted from `librdkafka`) Modifications: * add `allow.auto.create.topics` option to `KafkaProducerConfig` * * improve documetantation for allowAutoCreateTopics
1 parent fc4bee7 commit 4470f69

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Sources/SwiftKafka/Configuration/KafkaConsumerConfig.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ public struct KafkaConsumerConfig: Hashable, Equatable {
6565
set { self.dictionary["enable.auto.offset.store"] = String(newValue) }
6666
}
6767

68-
/// Allow automatic topic creation on the broker when subscribing to or assigning non-existent topics. The broker must also be configured with auto.create.topics.enable=true for this configuration to take effect. Note: the default value (true) for the producer is different from the default value (false) for the consumer. Further, the consumer default value is different from the Java consumer (true), and this property is not supported by the Java producer. Requires broker version >= 0.11.0.0, for older broker versions only the broker configuration applies.
68+
/// Allow automatic topic creation on the broker when subscribing to or assigning non-existent topics.
69+
/// The broker must also be configured with auto.create.topics.enable=true for this configuration to take effect.
70+
/// Default value: `false`
6971
public var allowAutoCreateTopics: Bool {
7072
get { self.dictionary.getBool("allow.auto.create.topics") ?? false }
7173
set { self.dictionary["allow.auto.create.topics"] = String(newValue) }

Sources/SwiftKafka/Configuration/KafkaProducerConfig.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ public struct KafkaProducerConfig: Hashable, Equatable {
5959
set { self.dictionary["message.send.max.retries"] = String(newValue) }
6060
}
6161

62+
/// Allow automatic topic creation on the broker when producing to non-existent topics.
63+
/// The broker must also be configured with auto.create.topics.enable=true for this configuration to take effect.
64+
/// Default value: `true`
65+
public var allowAutoCreateTopics: Bool {
66+
get { self.dictionary.getBool("allow.auto.create.topics") ?? true }
67+
set { self.dictionary["allow.auto.create.topics"] = String(newValue) }
68+
}
69+
6270
// MARK: - Common Client Config Properties
6371

6472
/// Client identifier.
@@ -295,6 +303,7 @@ public struct KafkaProducerConfig: Hashable, Equatable {
295303
queueBufferingMaxKBytes: UInt = 1_048_576,
296304
queueBufferingMaxMs: UInt = 5,
297305
messageSendMaxRetries: UInt = 2_147_483_647,
306+
allowAutoCreateTopics: Bool = true,
298307
clientID: String = "rdkafka",
299308
bootstrapServers: [String] = [],
300309
messageMaxBytes: UInt = 1_000_000,
@@ -338,6 +347,7 @@ public struct KafkaProducerConfig: Hashable, Equatable {
338347
self.queueBufferingMaxKBytes = queueBufferingMaxKBytes
339348
self.queueBufferingMaxMs = queueBufferingMaxMs
340349
self.messageSendMaxRetries = messageSendMaxRetries
350+
self.allowAutoCreateTopics = allowAutoCreateTopics
341351
self.clientID = clientID
342352
self.bootstrapServers = bootstrapServers
343353
self.messageMaxBytes = messageMaxBytes

0 commit comments

Comments
 (0)