Forward to event hub

Adding an Event Hub sink to Stream Analytics is very simple! Did you expect otherwise? To do so, first add a new Event Hub to your subscription. For scale, select the Basic messaging tier with one throughput unit to limit costs. When you create an Event Hub in the portal, you get:

You still need to click the + Event Hub link to actually create the Event Hub (notice the event hubs count above is 0). Give the Event Hub a name and leave the partition count on 2. Then click Create. When the creation succeeds and you refresh your view, the event hub count under namespace contents will be set to 1.

Next, stop the streaming job and add an extra output (sink) of type Event Hub. You can simply set Import option to Use event hub from current subscription and then select the service bus namespace and event hub name you created. As partition key column I use the device column and as event serialization format I use JSON (line separated instead of as a JSON array):

When the sink is added, change the query as follows:

SELECT
    temperature, humidity, co2, tvoc, 
    System.TimeStamp AS time, gebaAirQ.IoTHub.ConnectionDeviceID AS device
INTO
    "gebaAirQ-blob"
FROM
    gebaAirQ TIMESTAMP BY EventEnqueuedUtcTime

SELECT
    AVG(temperature) AS avgTemp, AVG(humidity) AS avgHum, AVG(co2) AS avgCo2, AVG(tvoc) AS avgTvoc, 
    System.TimeStamp AS time, gebaAirQ.IoTHub.ConnectionDeviceID AS device
INTO
    "gebaAirQ-PBI"
FROM
    gebaAirQ TIMESTAMP BY EventEnqueuedUtcTime
GROUP BY
    gebaAirQ.IoTHub.ConnectionDeviceID, TumblingWindow(second, 30)

SELECT
    temperature, humidity, co2, tvoc, 
    System.TimeStamp AS time, gebaAirQ.IoTHub.ConnectionDeviceID AS device
INTO
    "gebaAirQ-eh"
FROM
    gebaAirQ TIMESTAMP BY EventEnqueuedUtcTime

The blob and Event Hub sink use exactly the same queries. Now start the streaming job so that we can check Event Hub data is coming in. To check if data is entering the Event Hub, use Service Bus Explorer:

To obtain the above view, you need run Service Bus Explorer (I used version 4.0.90) and then select the Actions > Create Event Hub Listener menu. You will be asked for the following:

  • Event Hub Connection String: get it from the Event Hub properties in the portal via Shared Access Policies
  • Event Hub Path: the name of the Event Hub (gebaairq-eh in my case)
  • Consumer Group: you can use $Default

Now that we know that the events end up properly in the Event Hub, we can configure the real-time service to connect to it. Head over to the next section to do so.

results matching ""

    No results matching ""