markusthoemmes commented on a change in pull request #2948: Programmatic lazy
creation of completedN and invokerN topics
URL:
https://github.com/apache/incubator-openwhisk/pull/2948#discussion_r149904019
##########
File path:
common/scala/src/main/scala/whisk/connector/kafka/KafkaMessagingProvider.scala
##########
@@ -35,4 +45,30 @@ object KafkaMessagingProvider extends MessagingProvider {
def getProducer(config: WhiskConfig, ec: ExecutionContext)(implicit logging:
Logging): MessageProducer =
new KafkaProducerConnector(config.kafkaHost, ec)
+
+ def ensureTopic(config: WhiskConfig, topic: String, topicConfig: Map[String,
String])(
+ implicit logging: Logging): Boolean = {
+ val props = new Properties
+ props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, config.kafkaHost)
+ val client = AdminClient.create(props)
+ val numPartitions = topicConfig.getOrElse("numPartitions", "1").toInt
+ val replicationFactor = topicConfig.getOrElse("replicationFactor",
"1").toShort
+ val nt = new NewTopic(topic, numPartitions, replicationFactor)
+ .configs(topicConfig.-("numPartitions", "replicationFactor").asJava)
+ val results = client.createTopics(List(nt).asJava)
+ try {
+ results.values().get(topic).get()
+ logging.info(this, s"created topic $topic")
+ true
+ } catch {
+ case e: ExecutionException if
e.getCause().isInstanceOf[TopicExistsException] =>
Review comment:
`getCause` is an accessor --> drop the `()`
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services