卡夫卡+加特林+消费者场景

时间:2020-04-30 10:48:11

标签: apache-kafka gatling scala-gatling

我正试图编写一个消费者方案,试图使用加特林从kafka队列中读取一条消息来运行性能测试。

import io.gatling.core.Predef._<BR>
import org.apache.kafka.clients.consumer._<BR>
import org.apache.kafka.common.serialization.StringDeserializer<BR>
import java.util
<BR>
class BasicSimulation1 extends Simulation {

  val kafkaTopic = "test_topic_1"
  val kafkaBrokers = "localhost:9092"

  val props = new util.HashMap[String, Object]()
  props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, kafkaBrokers)
  props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
    classOf[StringDeserializer])
  props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
    classOf[StringDeserializer])
  props.put("group.id", "test-group")
  props.put("enable.auto.commit", "true")
  props.put("auto.commit.interval.ms", "1000")
  props.put("session.timeout.ms", "30000")

  val consumer = new KafkaConsumer[String, String](props)

  consumer.subscribe(java.util.Arrays.asList(kafkaTopic))

/*
  val scn = scenario("Kafka write Test")
            .exec(kafka("Simple Request").

  setUp(
    scn.inject(constantUsersPerSec(1) during(2 )))
    .protocols(props)*/

  while (true) {
    val records: ConsumerRecords[String, String] = consumer.poll(100)
    val recordsIterator = records.iterator()

    while (recordsIterator.hasNext) {
      val currentRecord: ConsumerRecord[String, String] = recordsIterator.next()
      println(currentRecord.value())
    }
  }
}

上面的代码面临问题:
无法完全为此编写方案,以便我可以在我的performance-test.gradle文件中使用BasicSimulation1运行方案

0 个答案:

没有答案