-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathAvroClassWithRequestReplySimulation.java
55 lines (46 loc) · 2.45 KB
/
AvroClassWithRequestReplySimulation.java
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
49
50
51
52
53
54
55
package ru.tinkoff.gatling.kafka.javaapi.examples;
import io.gatling.javaapi.core.*;
import org.apache.kafka.clients.producer.ProducerConfig;
import ru.tinkoff.gatling.kafka.javaapi.protocol.KafkaProtocolBuilderNew;
import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient;
import io.confluent.kafka.serializers.*;
import org.apache.kafka.common.serialization.*;
import ru.tinkoff.gatling.kafka.javaapi.request.builder.RequestReplyBuilder;
import java.time.Duration;
import java.util.*;
import static io.gatling.javaapi.core.CoreDsl.*;
import static ru.tinkoff.gatling.kafka.javaapi.KafkaDsl.kafka;
public class AvroClassWithRequestReplySimulation extends Simulation {
// example of using custom serde
public static Serializer<MyAvroClass> ser =
(Serializer) new KafkaAvroSerializer(new CachedSchemaRegistryClient(Arrays.asList("schRegUrl".split(",")), 16));
public static Deserializer<MyAvroClass> de =
(Deserializer) new KafkaAvroDeserializer(new CachedSchemaRegistryClient(Arrays.asList("schRegUrl".split(",")), 16));
// protocol
private final KafkaProtocolBuilderNew kafkaProtocolRRAvro = kafka().requestReply()
.producerSettings(
Map.of(
ProducerConfig.ACKS_CONFIG, "1",
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9093",
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringSerializer",
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "io.confluent.kafka.serializers.KafkaAvroSerializer",
// schema registry url is required for KafkaAvroSerializer and KafkaAvroDeserializer
"schema.registry.url", "http://localhost:9094"
)
)
.consumeSettings(
Map.of("bootstrap.servers", "localhost:9093")
)
.timeout(Duration.ofSeconds(5));
// message
public static RequestReplyBuilder<?, ?> kafkaMessage = kafka("RequestReply").requestReply()
.requestTopic("request.t")
.replyTopic("reply.t")
.send("key", new MyAvroClass(), String.class, MyAvroClass.class, ser, de);
// simulation
{
setUp(scenario("Kafka RequestReply Avro").exec(kafkaMessage).injectOpen(atOnceUsers(1))).protocols(kafkaProtocolRRAvro);
}
private static class MyAvroClass {
}
}