Consider this Kafka producer code snippet that sends a message to a topic in Confluent Cloud. What will be printed after successful message delivery?
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()
Think about the default partition assignment when no partition is specified.
By default, if no partition is specified, Kafka assigns the message to partition 0. So the delivery report prints the topic and partition 0.
Confluent Cloud provides several security features. Which one specifically ensures that data sent between clients and the cloud is encrypted?
Look for the protocol that combines authentication and encryption.
SASL_SSL combines SASL authentication with SSL encryption, ensuring data is encrypted during transit.
Review the following consumer code snippet. It connects to Confluent Cloud but does not receive any messages. What is the most likely cause?
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()
Notice that poll() is called only once with a 1.0 second timeout.
A single call to poll(1.0) may time out before receiving the message due to potential network latency or broker processing delays in Confluent Cloud. Consumers typically poll in a loop.
Examine the following code snippet. What error will it raise when run?
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()
Check the required parameters for the produce() method.
The produce() method has 'value=None' as the default for the value parameter, so no error is raised and a message with null value is sent.
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?
The --partitions flag sets the number of partitions.
The command explicitly sets the topic to have 5 partitions.