@@ -41,6 +41,8 @@ case class KafkaConfig(replicationFactor: Short, consumerLagCheckInterval: Finit
41
41
object KafkaMessagingProvider extends MessagingProvider {
42
42
import KafkaConfiguration ._
43
43
44
+ private val topicPartitionsConfigKey = " partitions"
45
+
44
46
def getConsumer (config : WhiskConfig , groupId : String , topic : String , maxPeek : Int , maxPollInterval : FiniteDuration )(
45
47
implicit logging : Logging ,
46
48
actorSystem : ActorSystem ): MessageConsumer =
@@ -64,12 +66,13 @@ object KafkaMessagingProvider extends MessagingProvider {
64
66
65
67
Try (AdminClient .create(commonConfig + (AdminClientConfig .BOOTSTRAP_SERVERS_CONFIG -> config.kafkaHosts)))
66
68
.flatMap(client => {
67
- val partitions = topicConfig.getOrElse(" partitions" , " 1" ).toInt
68
- val nt = new NewTopic (topic, partitions, kafkaConfig.replicationFactor).configs(topicConfig.asJava)
69
+ val partitions = topicConfig.getOrElse(topicPartitionsConfigKey, " 1" ).toInt
70
+ val safeTopicConfig = topicConfig - topicPartitionsConfigKey
71
+ val nt = new NewTopic (topic, partitions, kafkaConfig.replicationFactor).configs(safeTopicConfig.asJava)
69
72
70
73
def createTopic (retries : Int = 5 ): Try [Unit ] = {
71
74
Try (client.listTopics().names().get())
72
- .map (topics =>
75
+ .flatMap (topics =>
73
76
if (topics.contains(topic)) {
74
77
Success (logging.info(this , s " $topic already exists and the user can see it, skipping creation. " ))
75
78
} else {
0 commit comments