Kafka Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

CLI create a topic in Kafka

A

kafka-topics.sh –zookeeper 127.0.0.1:2181 –topic my_topic –create –partitions 3 –replication-factor 2

1) must reference zookeeper
2) must define partitions & replication factor

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

What limits your replication factor?

A

Broker number. You cannot have a replication factor higher than the number of brokers you have set.

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

CLI list Kafka topics

A

kafka-topics.sh –zookeeper 127.0.0.1:2181 –list

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

CLI get info about a topic

A

kafka-topics.sh –zookeeper 127.0.0.1:2181 –topic my_topic –describe

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

CLI delete a topic

A

kafka-topics.sh –zookeeper 127.0.0.1:2181 –topic my_topic –delete
DON’T DO THIS ON WINDOWS

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

CLI create a producer

A

kafka-console-producer.sh –broker-list 127.0.0.1:9092 –topic my_topic (–producer-property acks=all)

script, specify broker and where to find them, topic (optional properties)

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

CLI get out of producer

A

ctrl + C

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

what happens when you produce to a topic that doesn’t exist?

A

Kafka creates the topic, sends the message when a leader becomes available.
Topic is created with default values (partitions 1, replication factor 1)

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

change default values for topics

A

edit the server.properties file (in text editor):

num,partitions=1 (change to custom setting)

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

CLI create consumer

A

kafka-console-consumer.sh –bootstrap-server 127.0.0.1:9092 –topic my_topic
(begins getting messages produced after this is run. For all, add “–from-beginning”)

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

CLI set consumer group

A

Every consumer is part of a group; Id is the name of our application.
kafka-console-consumer.sh –bootstrap-server 127.0.0.1:9092 –topic my_topic –group my-application

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

Why consumer groups?

A

Every consumer is part of a group; Id is the name of our application.
Members of a group share the load, do load balancing. You can have as many consumers in a group as you have partitions. If one consumer goes down, the others will automatically rebalance the load.

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

CLI consumer groups: 1) list groups, 2) get info about a group

A

1) kafka-consumer-groups.sh –bootstrap-server 127.0.0.1:9092 –list
2) –describe –group my-application

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

CLI reset offset in a consumer group

A

Tell kafka where the group should start reading. (see options with kafka-consumer-groups.sh) (Shift forward or backwards with num or -num.)

  • specify group, where to rest offsets, topic
  • execute

kafka-consumer-groups.sh –bootstrap-server 127.0.0.1:9092 –group my-application –reset-offsets –to-earliest –execute –topic my_topic

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

What dependencies does Kafka need in Java POM?

A

1) Kafka-clients (not just kafka)

2) slf4j-simple (for logging) and remove scope

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

Java: define the steps to create a producer

A

1) set producer properties (Properties p = new Properties();
2) create producer
3) create producer record (the thing to send)
4) send record

17
Q

Java: How to set up kafka properties?

A

1) Create new properties (Prop p = new Prop();
2) Go to Kafka documentation, producer configs
3) 3 props are required:
p.setProperty(“bootstrap.servers”, “127.0.0.1:9092”); (you can make the address:port an instance variable)
p.setProperty(“key.serializer”, StringSerializer.class.getName());
same for value

4) to make sure you are getting these right, replace the string in the first place in () with ProducerConfig.BOOTSTRAP_SERVERS_CONFIG. There will be an enum for all you configuration properties

18
Q

Java: set up producer

A

1) KafkaProducer kp = new KP(properties); where objects in <> are KEY, and VALUE, whatever type you want, and properties are those created before in same class.

19
Q

Java: send a message

A

1) ProducerRecord pr = new PR(“some-topic”, “some-value”);
2) producer.send(record);
3) producer.flush(); //pushes out the record (or if you want to close, producer.close() which will flush and close)