0
0
Kafkadevops~10 mins

Confluent Cloud overview 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 in Confluent Cloud.

Kafka
from confluent_kafka import Producer

conf = {'bootstrap.servers': '[1]', 'sasl.mechanism': 'PLAIN'}
producer = Producer(conf)
Drag options to blanks, or click blank then click option'
Apkc-xyz.us-west1.gcp.confluent.cloud:9092
Blocalhost:9092
C127.0.0.1:9092
Dkafka:9092
Attempts:
3 left
💡 Hint
Common Mistakes
Using localhost or 127.0.0.1 instead of the cloud endpoint.
Omitting the port number 9092.
2fill in blank
medium

Complete the code to send a message to a topic in Confluent Cloud.

Kafka
producer.produce('[1]', key='key1', value='Hello, Confluent!')
producer.flush()
Drag options to blanks, or click blank then click option'
Aconfluent_topic
Btest_topic
Cmy_topic
Dcloud_topic
Attempts:
3 left
💡 Hint
Common Mistakes
Using a topic name that does not exist in the cloud cluster.
Leaving the topic name blank.
3fill in blank
hard

Fix the error in the configuration to connect securely to Confluent Cloud.

Kafka
conf = {
  'bootstrap.servers': 'pkc-xyz.us-west1.gcp.confluent.cloud:9092',
  'security.protocol': '[1]',
  'sasl.mechanism': 'PLAIN',
  'sasl.username': 'API_KEY',
  'sasl.password': 'API_SECRET'
}
Drag options to blanks, or click blank then click option'
APLAINTEXT
BSSL
CSASL_SSL
DSASL_PLAINTEXT
Attempts:
3 left
💡 Hint
Common Mistakes
Using PLAINTEXT or SSL without SASL.
Using SASL_PLAINTEXT which is insecure and not supported.
4fill in blank
hard

Fill both blanks to create a consumer that subscribes to a topic and polls messages.

Kafka
from confluent_kafka import Consumer

conf = {
  'bootstrap.servers': 'pkc-xyz.us-west1.gcp.confluent.cloud:9092',
  'group.id': '[1]',
  'auto.offset.reset': '[2]',
  'security.protocol': 'SASL_SSL',
  'sasl.mechanism': 'PLAIN',
  'sasl.username': 'API_KEY',
  'sasl.password': 'API_SECRET'
}
consumer = Consumer(conf)
consumer.subscribe(['test_topic'])
Drag options to blanks, or click blank then click option'
Amy_group
Bearliest
Clatest
Ddefault
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'default' which is not a valid offset reset value.
Not setting a group id.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps topic names to their partition counts if partitions are more than 1.

Kafka
topics = {'topic1': 1, 'topic2': 3, 'topic3': 2}
partition_map = { [1]: [2] for [3] in topics if topics[[3]] > 1 }
Drag options to blanks, or click blank then click option'
Atopic
Btopics[topic]
Dpartitions
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name not defined in the loop.
Mixing keys and values incorrectly.