# Azure Event Hubs

Below instructions help you connecting your Azure Event Hubs to KPN Things.

Don't have an Azure Event Hubs yet? Head on over to the Microsoft documentation on Azure Event Hubs:

{% embed url="<https://docs.microsoft.com/azure/event-hubs/event-hubs-create>" %}

## Connect an Azure Event Hubs

The following parameters are available to connect an Azure Event Hubs

| **Parameter**                               | **Description**                             | **Example value**                                                    |
| ------------------------------------------- | ------------------------------------------- | -------------------------------------------------------------------- |
| `name` \*                                   | The name of the destination                 | *My Event Hub*                                                       |
| `description` \*                            | Description of the destination              |                                                                      |
| `url` \*                                    | URL of your Event Hubs Namespace            | <p><em><https://myhubs>.</em><br><em>servicebus.windows.net</em></p> |
| `nameSpaceName` \*                          | The name of your Event Hubs Namespace       | *myhubs*                                                             |
| `Event Hubs instance` \* (event space name) | The name of your Event Hubs Instance        | *myeventhub*                                                         |
| `Policy name (sasKeyName)` \*               | SAS Policy name for key with claim "Manage" | *myeventhubKey*                                                      |
| `sasKey` \*†                                | Primary key for used SAS Policy             | *d2llZGl0bGpc2dlaw==*                                                |

*\*) required value*\
\&#xNAN;*†) secret value, write only, not returned by our systems*

## Where to find the required configuration values in the Azure Portal?

### Host name and Namespace

Open the **Overview page** of your Event Hubs Namespace in your Azure Portal. You will find the *host name* of your namespace (#1 in the screenshot) and the *Event Hubs* N*amespace* (#2 in the screenshot) as highlighted in the screenshot below.

Can't see the Host name? In the Dutch user interface, it is not visible. Switch to English language to see the host name in the Overview page.

<figure><img src="https://1453626848-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl6RrePMSAjRvOgcHjMBZ%2Fuploads%2FL1HZS0GJMjNh2HOX8Sta%2Fimage.png?alt=media&#x26;token=7618bfa5-228d-4979-a342-40eb69677b6f" alt=""><figcaption></figcaption></figure>

Now, use this value to make the following input values for the Azure Event Hubs destination configuration:

* **Host name**: should be of the form `https://X.servicebus.windows.net`, so put `https://` before your host name and you're done.
* **Event Hubs Namespace**: should be the name of your namespace.

### Event Hubs Instance / Event space name

Continue by clicking on **Event Hubs** under Entities in the left menu of your Namespace. Select the Event Hub Instance you would like to connect to. This opens the Overview page of your Event Hubs Instance. Here you will find the name of your Event Hubs Instance, also known as Event Space Name, as highlighted in the screenshot below:

<figure><img src="https://1453626848-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl6RrePMSAjRvOgcHjMBZ%2Fuploads%2FesSEZMQUfFTpqlflh9cS%2Fimage.png?alt=media&#x26;token=297faa5e-08f7-480e-833a-578181def4fa" alt=""><figcaption></figcaption></figure>

* **SAS Policy name**: #1 in the screenshot above highlights the SAS key name of a selected Policy.
* **SAS Primary key**: #2 in the screenshot above highlights the SAS key of a selected Policy.

## What does the connection do?

All IoT Data from devices linked to the destination is forwarded to the Event Hub in [SenML](https://docs.kpnthings.com/kpn-things/building-blocks/data-processing/thingsml-and-senml/senml) JSON format. Since the Azure Event Hubs in itself does not allow you to look into the data coming from KPN Things, we give two easy examples of how to debug IoT data landing in your Event Hub.

### Example for data debugging #1: Capture

Using the [Capture feature of your Event Hub](https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-capture-overview), you can store incoming data in an Azure Storage Container. In the screenshot below it is shown how raw LoRa payload can be found in the `avro` files generated by the capture feature.

<figure><img src="https://1453626848-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl6RrePMSAjRvOgcHjMBZ%2Fuploads%2F2dPj1vXdMVT4kyjnwJZ2%2Fimage.png?alt=media&#x26;token=a7eaed1e-7ba1-4cfb-848d-f1701e51f68f" alt=""><figcaption></figcaption></figure>

### Example for data debugging #2: Process data explorer (Query)

You can use SQL-like queries to explore your Event Hub data in the Process data feature. In the screenshot below it is shown how raw LoRa payload can be found in the data explorer.

<figure><img src="https://1453626848-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl6RrePMSAjRvOgcHjMBZ%2Fuploads%2FrCkCvKBzIeGdnW3t6Awb%2Fimage.png?alt=media&#x26;token=9480681c-a9f4-4bd8-83c0-f75614dd4a08" alt=""><figcaption></figcaption></figure>
