Using Funnel to send data to Azure Event Hubs

Soracom Funnel allows you to transfer data from a device to specific cloud services over cellular. In this guide, we'll cover how to use Funnel in order to send data to Azure Event Hubs.

Prerequisites


Configure Azure Event Hubs

1. Create an Event Hub

Follow the instructions in the following quickstart guide in order to create a Resource Group, an Event Hubs Namespace, and an Event Hub:

Azure Quickstart - Create an event hub using the Azure portal | Microsoft Docs

Once you have created an Event Hubs Namespace, make a note of its Host name:

https://portal.azure.com

Event Hubs Namespace

You will also need to make a note of the name of the Event Hub itself, created at the end of the quickstart guide:

https://portal.azure.com

Event Hub Name


2. Create a Shared Access Policy

Next, we need to create a set of credentials for Soracom Funnel to use in order to send data to the Event Hub.

Now we are ready to configure Soracom Funnel. Before we move on, let's quickly review the settings that we set up on Azure Event Hubs:


Configure Soracom Funnel

Now we can head over to the Soracom User Console and set up the connection between Funnel and Event Hub.

3. Add a Funnel Configuration

Let's open the group which contains our Soracom Air SIM in order to set up Funnel. You can either click the name of the group from the SIM Management page, or from the Groups page.


Test the connection

Now that Funnel is configured, any data that is sent from a Soracom Air SIM device within this group to a Funnel endpoint will be forwarded to our Event Hub.

Funnel has several endpoints which can be used to send data using several different types of protocols:

4. Send test data

In this example, our device with Soracom Air SIM is running Linux. In order to send the following data to Event Hub through Funnel:

{
  "deviceid": "iot123",
  "temp" : 4.12,
  "humidity": 80.43,
  "coords": {
    "latitude": 27.9881,
    "longitude": 86.9250
  }
}

All we have to do is send it using the curl command:

curl -v \
>  -H 'Content-Type: application/json' \
>  -d '{
>        "deviceid": "iot123",
>        "temp" : 4.12,
>        "humidity": 80.43,
>        "coords": {
>          "latitude": 27.9881,
>          "longitude": 86.9250
>        }
>      }' \
>  funnel.soracom.io

Because we are running the curl command with the verbose -v flag, we can check the HTTP response from Funnel. If we see a 204 response code, then our data has been successfully sent to our Event Hub:

>* Connected to funnel.soracom.io (100.127.65.43) port 80 (#0)
>> POST / HTTP/1.1
>> Host: funnel.soracom.io
>> User-Agent: curl/7.64.0
>> Accept: */*
>> Content-Type: application/json
>> Content-Length: 181
>>
>* upload completely sent off: 181 out of 181 bytes
>< HTTP/1.1 204 No Content
>< Date: Fri, 20 Sep 2019 20:18:36 GMT
>< Connection: keep-alive
><
>* Connection #0 to host funnel.soracom.io left intact
>

If another HTTP response code is returned, check the format of the transmission data based on the error code.

Meanwhile, if we check our Event Hub overview dashboard, we will see that our message has been received:

https://portal.azure.com


Conclusion

Congratulations, you've successfully sent data from a device to Azure Event Hubs through Soracom Funnel. By using Funnel, notice how we didn't need to store the event hub endpoint or the credentials on the device. Since the connection between the device and Soracom's cloud is encrypted over cellular, we just had to configure the hop between Soracom and Azure. This means that devices can be deployed at scale without having to worry about managing credentials, endpoints, or compute resources needed to manage cryptographic handshakes.