Azure-Samples / event-hubs-dotnet-import-from-sql

Simple cloud app that pulls incremental records from a SQL Azure table and pushes to event hub
MIT License
31 stars 29 forks source link

services: event-hubs, cloud-services, sql-database platforms: dotnet author: spyrossak

SQL to Event Hub scenario

This scenario is pretty rare, and you should be sure that it applies to you before continuing! Generally speaking, if you are using Event Hubs, you are working with streaming data, which you may end up storing in SQL. This project deals with the opposite, taking data out of SQL and pushing it to an Event Hub. The reason this is rare is that the data stored in SQL is usually more static than dynamic, and it would make little sense to stream it anywhere. On occassion, however, you may actually need to do this. The anticipated scenario is one where a SQL table is being updated from some remote source, and you want those updates to be streamed so that they can be visualized or merged with other streaming data. The code in this project is an example of how to do this. It is not a supported solution, nor a recommended one, but simply an example to show you how it can be done.

For more information about this sample, see the Pulling data from SQL into an Azure Event Hub topic in this repository.

Prerequisites

Setup Tasks

Setting up the application once you have an Event Hub and its Connection String involves the following tasks, which will be described in greater detail below.

  1. Clone or copy the project to your machine
  2. Open the project solution in Visual Studio
  3. Edit App.config in the SqlToEventHub folder to provide the relevant source and target configuration data
  4. Build the project
  5. Publish the application to your Azure subscription
  6. Verify that data is coming in to your Event Hub from the SQL table

Editing App.config

All the parameters you need to specify to get this project to run are in the <appSettings> section of the App.config file. There are two sections, one for the SQL table you will poll for updates, and one for the event hub to which you will send those updates.

The SQL table information

In the <appSettings> section, enter

The Event Hub information

Also in the <appSettings> section, enter

Publishing the application

  1. In Visual Studio, right-click on 'WorkerRole' in Solution 'SqlToEventHub', and select Publish.
  2. In the Publish Azure Application, answer the following questions.
    • Name: [pick something unique]
    • Region: [pick same region as you used for the Event Hub]
    • Database server: no database
    • Database password: [leave suggested password]
  3. Click Publish, and wait until the status bar shows "Completed". At that point the application is running in your subscription, polling the SQL table for any records that have been added since the last time it was polled, and pushing those records to your Event Hub. From there, you can access with Stream Analytics or any other application as you would normally.