Kafka Java Flashcards

1
Q

Configure the security protocol

A

props.put(CommonClientConfigs.SECURITY_PROTOCOL_CONFIG, “SSL”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Configure the path to the truststore file

A

props.put( SslConfigs.SSL_TRUSTSTORE_LOCATION_CONFIG, );

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Configure the truststore password

A

props.put(SslConfigs.SSL_TRUSTSTORE_PASSWORD_CONFIG, “password”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Configure bootstrap server

A

props.put(
ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG,
“YOUR_KAFKA_BOOTSTRAP_HOST:YOUR_KAFKA_BOOTSTRAP_PORT”
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

set the consumer group ID

A

props.put(
ConsumerConfig.GROUP_ID_CONFIG,
“reportingSystem”
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

set the key deserializer

A

props.put(
ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
“org.apache.kafka.common.serialization.StringDeserializer”
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

set the value deserializer

A

props.put(
ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
“org.apache.kafka.common.serialization.IntegerDeserializer”
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

set the offset reset config

A

props.put(
ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
“earliest”
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Initialize Kafka consumer

A

Consumer consumer = new KafkaConsumer<>(configureProperties());

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Consume events from kafka consumer

A

while (true) {
ConsumerRecords records = consumer.poll(Duration.ofSeconds(10));

        for (ConsumerRecord record : records) {
            printRecord(record);

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Subscribe consumer on topi

A

consumer.subscribe(Collections.singletonList(“wind-turbine-production”));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Initialize Kafka producer

A

Producer producer = new KafkaProducer<>(
configureProperties()
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Final producer instruction

A

producer.close();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

List consumer config properties

A

1) Bootstrap server
2) key deserializer
3) value deserializer
4) ssl location
5) security protocol
6) ssl password
7) group id

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Steps for consuming events

A

1) Build config
2) Setup kafka consumer client
3) Subscribe to topics
4) Reapreatedly poll.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Topic creation YAML

A
apiVersion: kafka.strimzi.io/v1beta2
kind: KafkaTopic
metadata:
  name: call-detail-records
  labels:
    strimzi.io/cluster: my-cluster
spec:
  partitions: 12
  replicas: 2
  config:
    retention.ms: 604800000
    segment.bytes: 1073741824