Using Gatling to loop through line by line in a file and send one message at a time to Kafka -
i have file contains text this
{"content_type":"twitter","id":"77f985b0-a30a-11e5-8791-80000bc51f65","source_id":"676656486307639298","date":"2015-12-15t06:54:12.000z","text":"rt @kokodeikku_bot: ?????: ??,} {"content_type":"twitter","id":"7837a020-a30a-11e5-8791-80000bc51f65","source_id":"676656494700568576",} {"content_type":"twitter","id":"7838d8a0-a30a-11e5-8791-80000bc51f65","source_id":"676656507266703360",} i'm unable read each line @ time string kafka topic within scenario, since can't iterate on scenario in gatling.
here code
class kafkasimulation extends simulation { val line = source.fromfile(<passing locn of file>)("utf-8").getlines.mkstring("\n") // 1 way reading source file val br = new bufferedreader(new filereader("<passing locn of file>")) var line:string = "" while ({ line = br.readline() ; line != null } ) { //in while loop can print line line cant use while loop within scenario below println(listoflines.mkstring("\n")) } val kafkaconf = kafka // kafka topic name .topic("test") // kafka producer configs .properties( map( producerconfig.acks_config -> "1", // list of kafka broker hostname , port pairs producerconfig.bootstrap_servers_config -> "localhost:9092", // required since apache kafka 0.8.2.0 producerconfig.key_serializer_class_config -> "org.apache.kafka.common.serialization.bytearrayserializer", producerconfig.value_serializer_class_config -> "org.apache.kafka.common.serialization.bytearrayserializer")) val scn = scenario("kafka test") .exec(kafka("request") // message send .send(line.tostring())) //here if put line.tostring(), doesnt read line line instead post entire 3 lines 1 message setup( scn.inject(constantuserspersec(10) during (1 seconds))) .protocols(kafkaconf) } any tips how can iterate on file , read line line in scenario?
turn file 1 column csv feeder , use standard gatling way: feed record, send request, , repeat as want.
Comments
Post a Comment