-
Notifications
You must be signed in to change notification settings - Fork 25
/
AvroClassWithRequestReplySimulation.kt
48 lines (41 loc) · 1.89 KB
/
AvroClassWithRequestReplySimulation.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package ru.tinkoff.gatling.kafka.javaapi.examples
import io.gatling.javaapi.core.CoreDsl.*
import io.gatling.javaapi.core.Simulation
import org.apache.kafka.clients.producer.ProducerConfig
import ru.tinkoff.gatling.kafka.javaapi.*
import ru.tinkoff.gatling.kafka.javaapi.KafkaDsl.*
import ru.tinkoff.gatling.kafka.request.*
import java.time.Duration
class AvroClassWithRequestReplySimulation : Simulation() {
// example of using custom serde
val ser = KafkaAvroSerializer(CachedSchemaRegistryClient("schRegUrl".split(','), 16),) as Serializer<MyAvroClass>
val de = KafkaAvroDeserializer(CachedSchemaRegistryClient("schRegUrl".split(','), 16),) as Deserializer<MyAvroClass>
// protocol
val kafkaProtocolRRAvro = kafka()
.requestReply()
.producerSettings(
mapOf<String, Any>(
ProducerConfig.ACKS_CONFIG to "1",
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to "localhost:9092",
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG to "org.apache.kafka.common.serialization.StringSerializer",
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG to "io.confluent.kafka.serializers.KafkaAvroSerializer",
// schema registry url is required for KafkaAvroSerializer and KafkaAvroDeserializer
"schema.registry.url" to "url"
)
)
.consumeSettings(
mapOf<String, Any>(
"bootstrap.servers" to "localhost:9092"
)
)
.timeout(Duration.ofSeconds(5))
// message
val kafkaMessage = kafka("RequestReply").requestReply()
.requestTopic("request.t")
.replyTopic("reply.t")
.send("key", MyAvroClass(), String::class.java, MyAvroClass::class.java, ser, de)
// simulation
init {
setUp(scenario("Kafka scenario").exec(kafkaMessage).injectOpen(atOnceUsers(1))).protocols(kafkaProtocolRRAvro)
}
}