0
0
Kafkadevops~10 mins

Amazon MSK in Kafka - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Kafka producer that sends a message to an MSK topic.

Kafka
from kafka import KafkaProducer

producer = KafkaProducer(bootstrap_servers='[1]')
producer.send('my-topic', b'Hello MSK!')
producer.flush()
Drag options to blanks, or click blank then click option'
Ab-1.mskcluster.example.com:9092
Blocalhost:9092
C127.0.0.1:2181
Dmsk-cluster:2181
Attempts:
3 left
💡 Hint
Common Mistakes
Using localhost or 127.0.0.1 instead of the actual MSK broker endpoint.
Using the ZooKeeper port 2181 instead of the Kafka broker port 9092.
2fill in blank
medium

Complete the code to consume messages from an MSK topic named 'orders'.

Kafka
from kafka import KafkaConsumer

consumer = KafkaConsumer('orders', bootstrap_servers='[1]', auto_offset_reset='earliest')
for message in consumer:
    print(message.value.decode('utf-8'))
Drag options to blanks, or click blank then click option'
Alocalhost:9092
Bzookeeper.msk.local:2181
Cb-2.mskcluster.example.com:9092
Dmsk-broker:2181
Attempts:
3 left
💡 Hint
Common Mistakes
Using ZooKeeper address instead of Kafka broker address.
Using localhost when connecting to a remote MSK cluster.
3fill in blank
hard

Fix the error in the code to configure the Kafka producer with SSL for MSK.

Kafka
producer = KafkaProducer(bootstrap_servers='b-1.mskcluster.example.com:9092', security_protocol='[1]', ssl_cafile='/path/to/ca.pem')
Drag options to blanks, or click blank then click option'
ASASL_SSL
BSSL
CSASL_PLAINTEXT
DPLAINTEXT
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'PLAINTEXT' disables encryption.
Using SASL options without proper SASL configuration.
4fill in blank
hard

Fill both blanks to create a Kafka consumer that uses SASL authentication with MSK.

Kafka
consumer = KafkaConsumer('logs', bootstrap_servers='b-3.mskcluster.example.com:9092', security_protocol='[1]', sasl_mechanism='[2]', sasl_plain_username='user', sasl_plain_password='pass')
Drag options to blanks, or click blank then click option'
ASASL_SSL
BSASL_PLAINTEXT
CPLAIN
DGSSAPI
Attempts:
3 left
💡 Hint
Common Mistakes
Using PLAINTEXT or SASL_PLAINTEXT disables encryption.
Using GSSAPI without Kerberos setup.
5fill in blank
hard

Fill all three blanks to produce a dictionary comprehension that maps topic partitions to their latest offsets in MSK.

Kafka
offsets = { [1]: [2] for [3] in consumer.assignment() }
Drag options to blanks, or click blank then click option'
Apartition
Bconsumer.position(partition)
Doffset
Attempts:
3 left
💡 Hint
Common Mistakes
Using undefined variables.
Confusing partition and offset roles.