0
0
Kafkadevops~20 mins

Confluent Cloud overview in Kafka - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Confluent Cloud Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Kafka producer code snippet in Confluent Cloud?

Consider this Kafka producer code snippet that sends a message to a topic in Confluent Cloud. What will be printed after successful message delivery?

Kafka
from confluent_kafka import Producer

conf = {'bootstrap.servers': 'pkc-xyz.us-west1.gcp.confluent.cloud:9092',
        'security.protocol': 'SASL_SSL',
        'sasl.mechanisms': 'PLAIN',
        'sasl.username': 'API_KEY',
        'sasl.password': 'API_SECRET'}

producer = Producer(conf)

def delivery_report(err, msg):
    if err is not None:
        print(f'Message delivery failed: {err}')
    else:
        print(f'Message delivered to {msg.topic()} [{msg.partition()}]')

producer.produce('my_topic', value='value1', callback=delivery_report)
producer.flush()
AMessage delivery failed: Broker not available
BMessage delivered to my_topic [0]
CMessage delivered to my_topic [1]
DNo output printed
Attempts:
2 left
💡 Hint

Think about the default partition assignment when no partition is specified.

🧠 Conceptual
intermediate
1:30remaining
Which feature of Confluent Cloud ensures data is encrypted during transit?

Confluent Cloud provides several security features. Which one specifically ensures that data sent between clients and the cloud is encrypted?

ASASL_SSL
BSchema Registry
CKafka Connect
DKafka Streams
Attempts:
2 left
💡 Hint

Look for the protocol that combines authentication and encryption.

🔧 Debug
advanced
2:30remaining
Why does this Kafka consumer in Confluent Cloud fail to receive messages?

Review the following consumer code snippet. It connects to Confluent Cloud but does not receive any messages. What is the most likely cause?

Kafka
from confluent_kafka import Consumer

conf = {'bootstrap.servers': 'pkc-xyz.us-west1.gcp.confluent.cloud:9092',
        'security.protocol': 'SASL_SSL',
        'sasl.mechanisms': 'PLAIN',
        'sasl.username': 'API_KEY',
        'sasl.password': 'API_SECRET',
        'group.id': 'my_group',
        'auto.offset.reset': 'earliest'}

consumer = Consumer(conf)
consumer.subscribe(['my_topic'])

msg = consumer.poll(1.0)
if msg is None:
    print('No message received')
elif msg.error():
    print(f'Error: {msg.error()}')
else:
    print(f'Received message: {msg.value().decode("utf-8")}')

consumer.close()
AThe consumer is not polling long enough to receive messages
BThe consumer group ID is missing or incorrect
CThe topic name is misspelled in subscribe()
DThe API key or secret is invalid
Attempts:
2 left
💡 Hint

Notice that poll() is called only once with a 1.0 second timeout.

📝 Syntax
advanced
1:30remaining
What error does this Confluent Cloud Kafka producer code raise?

Examine the following code snippet. What error will it raise when run?

Kafka
from confluent_kafka import Producer

conf = {'bootstrap.servers': 'pkc-xyz.us-west1.gcp.confluent.cloud:9092',
        'security.protocol': 'SASL_SSL',
        'sasl.mechanisms': 'PLAIN',
        'sasl.username': 'API_KEY',
        'sasl.password': 'API_SECRET'}

producer = Producer(conf)

# Missing required argument 'value'
producer.produce('my_topic', key='key1')
producer.flush()
ATypeError: produce() missing 1 required positional argument: 'value'
BValueError: Topic name cannot be empty
CRuntimeError: Producer not initialized
DNo error, message sent with empty value
Attempts:
2 left
💡 Hint

Check the required parameters for the produce() method.

🚀 Application
expert
1:00remaining
How many partitions will the topic have after this Confluent Cloud CLI command?

You run this command to create a topic in Confluent Cloud:

ccloud kafka topic create my_topic --partitions 5 --config retention.ms=604800000

How many partitions will my_topic have?

A10
B1
C5
D0
Attempts:
2 left
💡 Hint

The --partitions flag sets the number of partitions.