Skip to content

Commit 9f62dce

Browse files
committed
Created structs for new ClientConfigs
Modifications: * created a protocol `ClientConfig` that defines all common configuration properties * created two interface implementations, `ConsumerConfig` and `ProducerConfig`
1 parent f3ca724 commit 9f62dce

File tree

3 files changed

+278
-0
lines changed

3 files changed

+278
-0
lines changed
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-kafka-gsoc open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the swift-kafka-gsoc project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of swift-kafka-gsoc project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
// TODO: getter for internal dict representation
16+
// TODO: Array to comma separated string
17+
// TODO: default values
18+
// TODO: dict add manually by key (unsafe api)?
19+
// TODO: support PEMs?
20+
// TODO: support OAuth?
21+
// TODO: List continues at group.id
22+
// TODO: DocC: inherit documentation?
23+
// TODO: DocC: take from lirbdkafka official documentation
24+
// TODO: Topic config -> see KafkaConfig in SwiftKafka
25+
// TODO: make IPAddressFamily etc. part of some ConfigProperty like type to avoid cluttering docc
26+
protocol ClientConfig: Hashable, Equatable {
27+
var clientID: String { get set }
28+
29+
var bootstrapServers: [String] { get set }
30+
31+
var messageMaxBytes: UInt { get set }
32+
var messageCopyMaxBytes: UInt { get set }
33+
34+
var recieveMessageMaxBytes: UInt { get set }
35+
var maxInFlightRequestsPerConnection: UInt { get set }
36+
var metadataMaxAgeMs: UInt { get set }
37+
38+
var topicMetadataRefreshIntervalMs: Int { get set }
39+
var topicMetadataRefreshFastIntervalMs: UInt { get set }
40+
var topicMetadataRefreshSparse: Bool { get set }
41+
var topicMetadataPropagationMaxMs: UInt { get set } // TODO: needed?
42+
var topicDenylist: [String] { get set } // TODO: is blacklist actually + property needed?
43+
44+
var debug: [DebugOption] { get set }
45+
46+
var socketTimeoutMs: UInt { get set }
47+
var socketSendBufferBytes: UInt { get set }
48+
var socketReceiveBufferBytes: UInt { get set }
49+
var socketKeepaliveEnable: Bool { get set }
50+
var socketNagleDisable: Bool { get set }
51+
var socketMaxFails: UInt { get set }
52+
var socketConnectionSetupTimeoutMs: UInt { get set } // TODO: needed? if not also delete in implementing structs
53+
54+
var brokerAddressTTL: UInt { get set } // TODO: needed?
55+
var brokerAddressFamily: IPAddressFamily { get set }
56+
57+
var reconnectBackoffMs: UInt { get set }
58+
var reconnectBackoffMaxMs: UInt { get set }
59+
60+
var allowAutoCreateTopics: Bool { get set } // TODO: needed?
61+
62+
var securityProtocol: SecurityProtocol { get set }
63+
64+
var sslKeyLocation: String { get set }
65+
var sslKeyPassword: String { get set }
66+
var sslCertificateLocation: String { get set }
67+
var sslCALocation: String { get set }
68+
var sslCRLLocation: String { get set }
69+
var sslKeystoreLocation: String { get set }
70+
var sslKeystorePassword: String { get set }
71+
72+
var saslMechanism: SASLMechanism { get set }
73+
var saslUsername: String { get set }
74+
var saslPassword: String { get set }
75+
}
76+
77+
// MARK: - Auxiliary Types
78+
79+
public struct DebugOption: Hashable, Equatable, CustomStringConvertible {
80+
public let description: String
81+
82+
public static let generic = DebugOption(description: "generic")
83+
public static let broker = DebugOption(description: "broker")
84+
public static let topic = DebugOption(description: "topic")
85+
public static let metadata = DebugOption(description: "metadata")
86+
public static let feature = DebugOption(description: "feature")
87+
public static let queue = DebugOption(description: "queue")
88+
public static let msg = DebugOption(description: "msg")
89+
public static let `protocol` = DebugOption(description: "protocol")
90+
public static let cgrp = DebugOption(description: "cgrp")
91+
public static let security = DebugOption(description: "security")
92+
public static let fetch = DebugOption(description: "fetch")
93+
public static let interceptor = DebugOption(description: "interceptor")
94+
public static let plugin = DebugOption(description: "plugin")
95+
public static let consumer = DebugOption(description: "consumer")
96+
public static let admin = DebugOption(description: "admin")
97+
public static let eos = DebugOption(description: "eos")
98+
public static let all = DebugOption(description: "all")
99+
}
100+
101+
public struct IPAddressFamily: Hashable, Equatable, CustomStringConvertible {
102+
public let description: String
103+
104+
public static let any = IPAddressFamily(description: "any")
105+
public static let v4 = IPAddressFamily(description: "v4")
106+
public static let v6 = IPAddressFamily(description: "v6")
107+
}
108+
109+
public struct SecurityProtocol: Hashable, Equatable, CustomStringConvertible {
110+
public let description: String
111+
112+
public static let plaintext = SecurityProtocol(description: "plaintext")
113+
public static let ssl = SecurityProtocol(description: "ssl")
114+
public static let saslPlaintext = SecurityProtocol(description: "sasl_plaintext")
115+
public static let saslSSL = SecurityProtocol(description: "sasl_ssl")
116+
}
117+
118+
public struct SASLMechanism: Hashable, Equatable, CustomStringConvertible {
119+
public let description: String
120+
121+
public static let gssapi = SASLMechanism(description: "GSSAPI")
122+
public static let plain = SASLMechanism(description: "PLAIN")
123+
public static let scramSHA256 = SASLMechanism(description: "SCRAM-SHA-256")
124+
public static let scramSHA512 = SASLMechanism(description: "SCRAM-SHA-512")
125+
public static let oauthbearer = SASLMechanism(description: "OAUTHBEARER")
126+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-kafka-gsoc open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the swift-kafka-gsoc project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of swift-kafka-gsoc project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
public struct ConsumerConfig: ClientConfig {
16+
// TODO: some properties missing, check with franz
17+
18+
public var groupID: String = "" // TODO: how to handle assignment / subscription?
19+
public var sessionTimeoutMs: UInt = 45000
20+
public var heartbeatIntervalMs: UInt = 3000
21+
public var maxPollInvervalMs: UInt = 300000
22+
public var enableAutoCommit: Bool = true
23+
public var autoCommitIntervalMs: UInt = 5000
24+
public var enableAutoOffsetStore: Bool = true
25+
public var enablePartitionEOF: Bool = false
26+
27+
// MARK: - ClientConfig
28+
29+
public var clientID: String = "rdkafka"
30+
31+
public var bootstrapServers: [String] = []
32+
33+
public var messageMaxBytes: UInt = 1000000
34+
public var messageCopyMaxBytes: UInt = 65535
35+
36+
public var recieveMessageMaxBytes: UInt = 100000000
37+
public var maxInFlightRequestsPerConnection: UInt = 1000000
38+
public var metadataMaxAgeMs: UInt = 900000
39+
40+
public var topicMetadataRefreshIntervalMs: Int = 300000
41+
public var topicMetadataRefreshFastIntervalMs: UInt = 250
42+
public var topicMetadataRefreshSparse: Bool = true
43+
public var topicMetadataPropagationMaxMs: UInt = 30000
44+
public var topicDenylist: [String] = []
45+
46+
public var debug: [DebugOption] = []
47+
48+
public var socketTimeoutMs: UInt = 60000
49+
public var socketSendBufferBytes: UInt = 0
50+
public var socketReceiveBufferBytes: UInt = 0
51+
public var socketKeepaliveEnable: Bool = false
52+
public var socketNagleDisable: Bool = false
53+
public var socketMaxFails: UInt = 1
54+
public var socketConnectionSetupTimeoutMs: UInt = 30000
55+
56+
public var brokerAddressTTL: UInt = 1000
57+
public var brokerAddressFamily: IPAddressFamily = .any
58+
59+
public var reconnectBackoffMs: UInt = 100
60+
public var reconnectBackoffMaxMs: UInt = 10000
61+
62+
public var allowAutoCreateTopics: Bool = false
63+
64+
public var securityProtocol: SecurityProtocol = .plaintext
65+
66+
public var sslKeyLocation: String = ""
67+
public var sslKeyPassword: String = ""
68+
public var sslCertificateLocation: String = ""
69+
public var sslCALocation: String = ""
70+
public var sslCRLLocation: String = ""
71+
public var sslKeystoreLocation: String = ""
72+
public var sslKeystorePassword: String = ""
73+
74+
public var saslMechanism: SASLMechanism = .gssapi
75+
public var saslUsername: String = ""
76+
public var saslPassword: String = ""
77+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the swift-kafka-gsoc open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the swift-kafka-gsoc project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of swift-kafka-gsoc project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
public struct ProducerConfig: ClientConfig {
16+
// TODO: some properties missing, check with franz
17+
public var transactionalID: String = "" // TODO: Use empty string or nil for "no value"?
18+
public var transactionalTimeoutMs: UInt = 60000
19+
public var enableIdempotence: Bool = false
20+
public var queueBufferingMaxMessages: UInt = 100000
21+
public var queueBufferingMaxKBytes: UInt = 1048576
22+
public var queueBufferingMaxMs: UInt = 5
23+
public var messageSendMaxRetries: UInt = 2147483647
24+
25+
// MARK: - ClientConfig
26+
27+
public var clientID: String = "rdkafka"
28+
29+
public var bootstrapServers: [String] = []
30+
31+
public var messageMaxBytes: UInt = 1000000
32+
public var messageCopyMaxBytes: UInt = 65535
33+
34+
public var recieveMessageMaxBytes: UInt = 100000000
35+
public var maxInFlightRequestsPerConnection: UInt = 1000000
36+
public var metadataMaxAgeMs: UInt = 900000
37+
38+
public var topicMetadataRefreshIntervalMs: Int = 300000
39+
public var topicMetadataRefreshFastIntervalMs: UInt = 250
40+
public var topicMetadataRefreshSparse: Bool = true
41+
public var topicMetadataPropagationMaxMs: UInt = 30000
42+
public var topicDenylist: [String] = []
43+
44+
public var debug: [DebugOption] = []
45+
46+
public var socketTimeoutMs: UInt = 60000
47+
public var socketSendBufferBytes: UInt = 0
48+
public var socketReceiveBufferBytes: UInt = 0
49+
public var socketKeepaliveEnable: Bool = false
50+
public var socketNagleDisable: Bool = false
51+
public var socketMaxFails: UInt = 1
52+
public var socketConnectionSetupTimeoutMs: UInt = 30000
53+
54+
public var brokerAddressTTL: UInt = 1000
55+
public var brokerAddressFamily: IPAddressFamily = .any
56+
57+
public var reconnectBackoffMs: UInt = 100
58+
public var reconnectBackoffMaxMs: UInt = 10000
59+
60+
public var allowAutoCreateTopics: Bool = true
61+
62+
public var securityProtocol: SecurityProtocol = .plaintext
63+
64+
public var sslKeyLocation: String = ""
65+
public var sslKeyPassword: String = ""
66+
public var sslCertificateLocation: String = ""
67+
public var sslCALocation: String = ""
68+
public var sslCRLLocation: String = ""
69+
public var sslKeystoreLocation: String = ""
70+
public var sslKeystorePassword: String = ""
71+
72+
public var saslMechanism: SASLMechanism = .gssapi
73+
public var saslUsername: String = ""
74+
public var saslPassword: String = ""
75+
}

0 commit comments

Comments
 (0)