Tutorial: Receive Data in Your Event Hub
This tutorial will show you how to route data to an Event Hub and consume it. You will:
- Create an Event Hub Egress Sink
- Configure a Stream to forward data to the Egress Sink
- Send data to the Platform and consume it from the Event Hub
Requirements
- .NET 8.
- If you are not registered to the Spotflow IoT Platform yet, Sign Up.
- You need to have an existing Stream.
A Stream called
default-stream
in Stream Groupdefault-stream-group
is created automatically after you register. Create a new one if you want to use a different Stream. - You need to have an existing Event Hub and Storage Account for checkpointing.
1. Route Data to a New Event Hub Egress Sink
Event Hub Egress Sink represents an existing Event Hub to which the Platform can forward data. Let's create a new one and configure a stream to forward data to it.
- Portal
- CLI
- API
Click on Data Flows in the left sidebar.
Click on the Add Route button next to the stream that should be routed to the Event Hub.
Choose the Create a New Egress Sink option and click on the Next button.
Fill the name of the Egress Sink, e.g.
my-eventhub
. SelectAzure Event Hub
as the egress sink kind. And finally, paste the connection string to your eventhub into the respective input field. Click Create Egress Sink and Continue.The new Event Hub Egress Sink is now created! At this point, it is only needed to create an egress route so the data from your stream are forwarded to this sink. Review the default configuration and optionally customize it. Click Create Egress Route to finish.
The route to the new Event Hub Egress Sink has been created! You should see an arrow going from your stream to the Egress Sink.
Create Event Hub Egress Sink
Supposing you have already installed the CLI and logged in, replace the placeholders <Your Egress Sink Name>
and <Your Event Hub Connection String>
with your Event Hub Egress Sink name and your Event Hub connection string and run the following command to create a new Event Hub Egress Sink:
spotf egress-sink create-or-update eh -n <Your Egress Sink Name> -c "<Your Event Hub Connection String>"
The CLI will confirm the creation and display the Event Hub Egress Sink details:
Name: my-event-hub-sink
WorkspaceId: 925d28eb-e162-47db-bdd0-4a7028e177fc
Properties
├── IsEnabled: true
└── Config
└── AzureEventHub
├── Endpoint: sb://myeventhub.servicebus.windows.net/
├── EventHubName: myeventhub
└── SharedAccessKeyName: Write
Create Route to the Egress Sink
Run the following command:
spotf stream route cu eh -g my-new-stream-group -s my-new-stream -n route-to-event-hub -k my-event-hub-sink
The CLI will confirm the creation and display the Egress Route details:
Name: route-to-event-hub
WorkspaceId: 925d28eb-e162-47db-bdd0-4a7028e177fc
StreamGroupName: my-new-stream-group
StreamName: my-new-stream
Properties
├── IsEnabled: true
├── EgressSinkName: my-event-hub-sink
├── Config
│ └── AzureEventHub
│ ├── ForceExternalizedPayload: false