0
0
Azurecloud~10 mins

Event Hubs for streaming data in Azure - 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 an Event Hub client using the connection string.

Azure
from azure.eventhub import EventHubProducerClient

producer = EventHubProducerClient.from_connection_string(conn_str=[1], eventhub_name="myeventhub")
Drag options to blanks, or click blank then click option'
Amyeventhub
B"Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abc123"
CEventHubProducerClient
Dconnection_string
Attempts:
3 left
💡 Hint
Common Mistakes
Using the event hub name instead of the connection string.
Passing the client class name instead of the connection string.
Using a variable name without quotes.
2fill in blank
medium

Complete the code to send a batch of events to the Event Hub.

Azure
with producer:
    event_data_batch = producer.create_batch()
    event_data_batch.add(EventData('First event'))
    producer.[1](event_data_batch)
Drag options to blanks, or click blank then click option'
Areceive
Bcreate_batch
Csend_batch
Dclose
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'receive' which is for receiving events.
Calling 'create_batch' again instead of sending.
Calling 'close' which closes the client.
3fill in blank
hard

Fix the error in the code to receive events from the Event Hub.

Azure
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)
Drag options to blanks, or click blank then click option'
A"Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abc123"
B"myeventhub"
Con_event
Dconsumer_group
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the event hub name instead of the connection string.
Passing the consumer group instead of the connection string.
Passing the callback function instead of the connection string.
4fill in blank
hard

Fill both blanks to create a batch and add multiple events before sending.

Azure
with producer:
    batch = producer.[1]()
    batch.[2](EventData('Event 1'))
    batch.add(EventData('Event 2'))
    producer.send_batch(batch)
Drag options to blanks, or click blank then click option'
Acreate_batch
Bsend_batch
Cadd
Dreceive
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'send_batch' to create a batch.
Using 'receive' to add events.
Using 'send_batch' to add events.
5fill in blank
hard

Fill all three blanks to receive events with a consumer client and start receiving.

Azure
consumer = EventHubConsumerClient.from_connection_string(conn_str=[1], consumer_group=[2], eventhub_name=[3])

consumer.receive(on_event=on_event)
Drag options to blanks, or click blank then click option'
A"Endpoint=sb://mynamespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=abc123"
B"$Default"
C"myeventhub"
D"RootManageSharedAccessKey"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the shared access key instead of the connection string.
Using the event hub name as the consumer group.
Leaving any of the parameters as variables without quotes.