Skip to content

Instantly share code, notes, and snippets.

@srnagar
Created April 20, 2020 18:55
Show Gist options
  • Save srnagar/dd40207a806c05fbee76e49cb9eec154 to your computer and use it in GitHub Desktop.
Save srnagar/dd40207a806c05fbee76e49cb9eec154 to your computer and use it in GitHub Desktop.
IotHub connection string to Event Hub connection string

IoT Hub Connection String support in Event Hubs

Background:

Azure IotHub instances have built-in Event Hub instances configured for users to publish/consume events from their IotHub devices. The IotHub instance has a connection string that can be used to authenticate the IotHub instance but cannot be used to authenticate Event Hub instance directly as the endpoints are not the same. However, using the IotHub connection string, an Event Hub connection string can be constructed by getting the endpoint from Event Hub service.

History:

In track 1, Event Hub SDK had support for taking an IotHub connection string and internally converting it into Event Hub connection string. So, users had to simply use the IotHub connection string readily available on the portal to access Event Hub.

Current:

For track 2, the feature team decided that Event Hub SDK should not be coupled with IotHub. So, users cannot use IotHub connection string to connect to Event Hub. To fill this void, all languages instead will provide a sample program that will show how to convert an IotHub connection string to Event Hub connection string. Users are expected to then use this program to first convert the IotHub connection string to Event Hub connection string and then use this in Event Hub SDK.

Java:

For Java, providing this sample will require making a few public facing API changes as the conversion will require some additional capabilities that we currently don't expose to users. If we don't do these changes, providing a sample will require using proton-j library directly to do the conversion which will require duplicating a major part of azure-core-amqp in our sample. 

API Changes:

The API changes required for this conversion is in this PR - Azure/azure-sdk-for-java#10375

  • Add new credential() overload in client builder that allows users to provide their own token credential and specify the CBS authorization type (JWT or SAS). Currently, when users provide a token credential, it's always assumed that it is JWT.
  • Add new API to specify the entity path in client builder. IotHub's entity path is different from the entity path we generally use for Event Hubs. The prefix for IotHub is /messages/events/ and the prefix for Event Hub is the event hub name itself.
  • Missing error conditions in AmqpErrorCondition enum. Some error conditions are missing in AmqpErrorCondition.java that should be added regardless of this conversion sample.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment