Update sample to use latest version of Python Event Hubs package#24
Update sample to use latest version of Python Event Hubs package#24robinsh merged 5 commits intoAzure-Samples:masterfrom
Conversation
|
cc @elhorton, @jebrando, @JimacoMS3, @robinsh, @philmea This is similar to what was done to the Node sample in Azure-Samples/azure-iot-samples-node#39 |
|
|
||
| # If you have access to the Event Hub-compatible connection string from the Azure portal, then | ||
| # you can skip the Azure CLI commands above, and assign the connection string directly here. | ||
| CONNECTION_STR = f'Endpoint=sb://{EVENTHUB_COMPATIBLE_ENDPOINT}/;SharedAccessKeyName=service;SharedAccessKey={IOTHUB_SAS_KEY};EntityPath={EVENTHUB_COMPATIBLE_PATH}'; |
There was a problem hiding this comment.
You don't need the leading 'sb://' here. It's inlcuded in the EVENTHUB_COMPATIBLE_ENDPOINT. Also, I don't think you need/want the terminating semi-colon. Same things for the sync sample
There was a problem hiding this comment.
Sorry for the trailing ';'. I used VS code to create this sample. I realized it didn't save automatically like Pycharm so my last small fixes were not saved and pushed.
Corrected now.
| await client.receive_batch( | ||
| on_event_batch=on_event_batch, | ||
| on_error=on_error, | ||
| starting_position="-1", # "-1" is from the beginning of the partition. |
There was a problem hiding this comment.
Can we get rid of the starting_position parameter? This spits out a bunch of telemetry that could have happened before you actually ran the SimulatedDevice sample. I think getting rid of the parameter, just starts from the current time -- I think. Same thing for the sync sample.
There was a problem hiding this comment.
Removed. So it will only receive new messages.
|
|
||
| # If you have access to the Event Hub-compatible connection string from the Azure portal, then | ||
| # you can skip the Azure CLI commands above, and assign the connection string directly here. | ||
| CONNECTION_STR = f'Endpoint=sb://{EVENTHUB_COMPATIBLE_ENDPOINT}/;SharedAccessKeyName=service;SharedAccessKey={IOTHUB_SAS_KEY};EntityPath={EVENTHUB_COMPATIBLE_PATH}'; |
| client.receive_batch( | ||
| on_event_batch=on_event_batch, | ||
| on_error=on_error, | ||
| starting_position="-1", # "-1" is from the beginning of the partition. |
There was a problem hiding this comment.
See comment for async wrt starting_position.
| # Event Hub-compatible endpoint | ||
| # az iot hub show --query properties.eventHubEndpoints.events.endpoint --name {your IoT Hub name} | ||
| EVENTHUB_COMPATIBLE_ENDPOINT = "{your Event Hubs compatible endpoint}" | ||
| EVENTHUB_COMPATIBLE_ENDPOINT = "iothub-ns-yijun-ioth-3130889-4398262da5.servicebus.windows.net" |
There was a problem hiding this comment.
Don't forget to yank your hard-coded constants :)
There was a problem hiding this comment.
This is embarrassing. I used them to test the script.
Not saved file before git commit in VS code again.
I regenerated the key on portal as well since it's compromised.
Thanks for pointing this out.
There was a problem hiding this comment.
Just realized the resource was already deleted on github.
There was a problem hiding this comment.
I've done the same thing roughly a million times :)
|
doc updates in this PR: https://github.com/MicrosoftDocs/azure-docs-pr/pull/115889 (Note: screenshot needs updating.) |
|
@YijunXieMS Hi Yijun -- one last request here. Is it possible to have a graceful way to exit these samples (without adding a ton of code) ? Right now, ctrl-c generates exception output. (if that's something that's common across the EH samples, then don't worry about it). The other EH platform samples exit more gracefully. Thanks, Jimaco |
Hi Jimaco, yes I can add some code for ctrl-c within this week. |
|
Awesome Yi -- let me know when you have it ready. |
|
@YijunXieMS Thanks Yijun! Ctrl-c works great. Just one last nit (if you don't have time for this - just let me know). Can please add a line between groups of readings. I think it just makes it more easy to parse. i.e. This really is a nit. Like I said, if you don't have time - just let me know. |
|
@JimacoMS3 Added that extra line. Let me know if anything else. |
|
Thanks Yijun! |
|
#sign-off |
|
@robinsh - just signed-off please merge |

Purpose
Does this introduce a breaking change?
Pull Request Type
What kind of change does this Pull Request introduce?
How to Test
What to Check
Verify that the following are valid
Other Information