本文整理汇总了Scala中kafka.admin.AdminUtils类的典型用法代码示例。如果您正苦于以下问题:Scala AdminUtils类的具体用法?Scala AdminUtils怎么用?Scala AdminUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AdminUtils类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: KafkaConfiguratorFeatureSpec
//设置package包名称以及导入依赖的类
package com.sky.kafka.configurator
import common.KafkaIntSpec
import kafka.admin.AdminUtils
import org.scalatest.concurrent.Eventually
import scala.util.Success
class KafkaConfiguratorFeatureSpec extends KafkaIntSpec with Eventually {
"KafkaConfigurator" should "create new topics in Kafka from a file" in {
val args = Array(
"-f", getClass.getResource("/topic-configuration.yml").getPath,
"--zookeeper", s"localhost:${kafkaServer.zookeeperPort.toString}"
)
val topics = List("topic1", "topic2")
topics.map(AdminUtils.topicExists(zkUtils, _) shouldBe false)
Main.run(args) shouldBe Success(())
eventually {
withClue("Topic exists: ") {
topics.map(AdminUtils.topicExists(zkUtils, _) shouldBe true)
}
}
}
}
开发者ID:sky-uk,项目名称:kafka-configurator,代码行数:30,代码来源:KafkaConfiguratorSpec.scala
示例2: KafkaUtilities
//设置package包名称以及导入依赖的类
package com.fortysevendeg.log.utils
import java.util.Properties
import kafka.admin.AdminUtils
import kafka.producer.{KeyedMessage, Producer, ProducerConfig}
import kafka.utils.ZkUtils
import org.I0Itec.zkclient.ZkConnection
import org.apache.kafka.clients.consumer.KafkaConsumer
object KafkaUtilities {
def createKafkaProducer(): Producer[String, String] = {
val props = new Properties()
props.put("metadata.broker.list", "localhost:9092")
props.put("serializer.class", "kafka.serializer.StringEncoder")
// props.put("partitioner.class", "com.fortysevendeg.biglog.SimplePartitioner")
// props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer")
// props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")
props.put("producer.type", "async")
props.put("request.required.acks", "1")
val config = new ProducerConfig(props)
new Producer[String, String](config)
}
def createKafkaConsumer(): KafkaConsumer[String, String] = {
val props = new Properties()
props.put("bootstrap.servers", "localhost:9092")
props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer")
new KafkaConsumer[String, String](props)
}
def createTopicIntoKafka(topic: String, numPartitions: Int, replicationFactor: Int): Unit = {
val zookeeperConnect = "localhost:2181"
val sessionTimeoutMs = 10 * 1000
val connectionTimeoutMs = 8 * 1000
val zkClient = ZkUtils.createZkClient(zookeeperConnect, sessionTimeoutMs, connectionTimeoutMs)
val zkUtils = new ZkUtils(zkClient, zkConnection = new ZkConnection(zookeeperConnect), isSecure = false)
AdminUtils.createTopic(zkUtils, topic, numPartitions, replicationFactor, new Properties)
zkClient.close()
}
def d(kafkaProducer: Producer[String, String], topic: String, message: String) = {
kafkaProducer.send(new KeyedMessage[String, String](topic, message))
}
}
开发者ID:javipacheco,项目名称:spark-android-log,代码行数:52,代码来源:KafkaUtilities.scala
注:本文中的kafka.admin.AdminUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论