question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Azure Event Hub]- Sending Event Message with Partition Key of type int is DANGEROUS

See original GitHub issue

Hi, a few days ago I wrote script that sends the real time events to Event Hub. I used Azure Durable Functions to implement parallelism, and in doing so I used partition_key to ensure events with same id is directed to same partition. For some reason I thought the key can be single number and thus I used int types as partition keys, and while sending I never had any error about it. Later I implemented another function App that listens to Event Hub, and triggered when new message is received in Even Hub, and while doing so I was getting the following error at each firing: Unable to cast object of type 'System.Int32' to type 'System.String

At first I thought may be this is due to encoding of str files that send which took me quite a long time to figure out this was because my usage of int value as partition key due to which Event Hub backend could not generate partition key hashes.

I am wondering why no Exception is raised if int type is passed as partition_key argument at the time of sending message string, and may be this is bug to be considered.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
serkantkaracacommented, Jul 9, 2020

@YijunXieMS service ignores partition-key if it is not string type.

1reaction
jsquirecommented, Jul 8, 2020

Thank you, @aliyevmirzakhan.

Based on that, I think @johanste’s initial assessment is likely. The Azure Functions infrastructure is based on .NET and the bindings are running in the context of that infrastructure using the .NET Event Hubs client rather than running in the context of the Python language worker and using the Python SDK.

The root cause would appear to be that the partition key is enforced as string by the Track One and Track Two client libraries for all languages other than Python. The question, in my opinion, comes down to “should we guarantee that events published from a language can be read by the other languages and across versions of the SDK?”

Assuming so, I believe the choice comes down to:

  • Do we investigate whether there is a way to be looser with type checking and coerce non-string values to string in the non-Python libraries?
  • Do we introduce a breaking change to the Python library to validate the type matches the documentation?
  • Do we leave the Python behavior as-is and consider a stronger warning in documentation about cross-language compatibility?
  • Do we introduce breaking changes to the other libraries to allow a generic object value and, if so, does that include the track one libraries as well?

As @ramya-rao-a mentions, so long as the service team does not have a service-specific reason to disallow, the first is probably our most promising starting point. The tricky part of that will be that the Azure Functions bindings are still using the track one Event Hubs client.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to send data to a specific Azure Event Hub partition key
I have to send a specific message to a particular partition. for eg. "Message1" on Partition 1 "Message2" on Partition 2 "Message3" on...
Read more >
How to send data to an EventHub setting the PartitionId NOT ...
The REST API Send partition event requires the partitionId parameter in the endpoint https://{servicebusNamespace}.servicebus.windows.net/{ ...
Read more >
Azure Event Hub Messaging using REST - Tech Scout
Post talks about how you can use Azure Event Hub to publish high throughput messages any application/platform eg IOT.
Read more >
azure.eventhub package - NET
The EventData class is a container for event content. Parameters. body (str or bytes) – The data to send in a single message....
Read more >
Streaming Events to AzureML Through Azure Stream Analytics
I will also use a better method to push events to the eventhub. ... str(int(time.time())%10000000) item = {'PartitionKey': hostname, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found