Complete the code to create an Event Hub client using the connection string.
from azure.eventhub import EventHubProducerClient producer = EventHubProducerClient.from_connection_string(conn_str=[1], eventhub_name="myeventhub")
The connection string is required to authenticate and connect to the Event Hub namespace.
Complete the code to send a batch of events to the Event Hub.
with producer: event_data_batch = producer.create_batch() event_data_batch.add(EventData('First event')) producer.[1](event_data_batch)
The send_batch method sends the batch of events to the Event Hub.
Fix the error in the code to receive events from the Event Hub.
from azure.eventhub import EventHubConsumerClient consumer = EventHubConsumerClient.from_connection_string(conn_str=[1], consumer_group="$Default", eventhub_name="myeventhub") def on_event(partition_context, event): print(event.body_as_str()) consumer.receive(on_event=on_event)
The connection string is required to authenticate the consumer client.
Fill both blanks to create a batch and add multiple events before sending.
with producer: batch = producer.[1]() batch.[2](EventData('Event 1')) batch.add(EventData('Event 2')) producer.send_batch(batch)
You create a batch with create_batch() and add events with add().
Fill all three blanks to receive events with a consumer client and start receiving.
consumer = EventHubConsumerClient.from_connection_string(conn_str=[1], consumer_group=[2], eventhub_name=[3]) consumer.receive(on_event=on_event)
The consumer client needs the connection string, the consumer group name, and the event hub name to connect and receive events.