|
1 | 1 | ---
|
2 |
| -title: Pulling SQL data into Azure Event Hubs | Microsoft Docs |
3 |
| -description: Overview of the Event Hubs import from SQL sample |
4 |
| -services: event-hubs |
5 |
| -documentationcenter: na |
6 |
| -author: spyrossak |
7 |
| -manager: timlt |
8 |
| -editor: '' |
9 |
| - |
10 |
| -ms.assetid: 3dbc21f2-5e97-463f-85c8-78450369ca48 |
11 |
| -ms.service: event-hubs |
12 |
| -ms.devlang: na |
13 |
| -ms.topic: article |
14 |
| -ms.tgt_pltfrm: na |
15 |
| -ms.workload: na |
16 |
| -ms.date: 08/25/2016 |
17 |
| -ms.author: spyros;sethm |
18 |
| - |
19 |
| ---- |
20 |
| -# Pulling data from SQL into an Azure Event Hub |
21 |
| -A typical architecture for an application for processing real-time data involves |
22 |
| -first pushing it to an Azure Event Hub. It may be an IoT scenario, such as |
23 |
| -monitoring the traffic on different stretches of a highway, or a gaming scenario, monitoring |
24 |
| -the actions of a horde of frenzied contestants, or an enterprise scenario, such as |
25 |
| -monitoring building occupancy. In these cases, the data producers are generally external |
26 |
| -objects producing time-series data that you need to collect, analyse, store, and act upon, |
27 |
| -and you may have invested a lot of effort into building out the infrastructure for these |
28 |
| -processes. What do you do if you want to bring in data from something like a database rather |
29 |
| -than a source of streaming data, and use it in conjunction with your other streaming data? |
30 |
| -Consider the case where you want to use Azure Stream Analytics, Remote Data Explorer (RDX), or |
31 |
| -some other tool to analyze and act on slowly-changing data from Microsoft Dynamics AX or a |
32 |
| -custom facilities-management system? To solve this problem, we've written and open-sourced a small cloud |
33 |
| -sample that you can modify and deploy that will pull the data from a SQL table and push it |
34 |
| -to an Azure Event Hub to use as an input in your downstream analytical applications. Do realize that this is a |
35 |
| -rare scenario, and the opposite of what you normally do with an Event Hub. However, if you |
36 |
| -do find yourself in the situation where this is what you need to do, you can find the code in the Azure |
37 |
| -Samples gallery, [here](https://azure.microsoft.com/documentation/samples/event-hubs-dotnet-import-from-sql/). |
38 |
| - |
39 |
| -Note that the code in this sample is just that, a sample. It is **not** intended to be a production application, and no attempts have been made to make it suitable for use |
40 |
| -in such an environment - it is stricly a DIY, developer-focused, example. |
41 |
| -You need to review all sorts of security, performance, functionality, and cost factors before settling on |
42 |
| -an end-to-end architecture. |
43 |
| - |
44 |
| -## Application structure |
45 |
| -The application is written in C#, and the readme.md file in the sample contains all the information you need to |
46 |
| -modify, build, and publish the application. The following sections provide a high level overview of what the |
47 |
| -application does. |
48 |
| - |
49 |
| -We start with the assumption that you have access to a SQL Azure table. You'll also need to have set |
50 |
| -up an Azure Event Hub, and know the connection string needed to access it. |
51 |
| - |
52 |
| -When the SqlToEventHub solution starts up, it reads a configuration file (App.config) |
53 |
| -to get a number of things, as outlined in the readme.md file. These are pretty self-explanatory, |
54 |
| -such as the name of the data table, etc, and there is no need to rehash the explanations |
55 |
| -here. |
56 |
| - |
57 |
| -Once the application has read the config file, it goes into a loop, reading the SQL table and |
58 |
| -pushing records to the event hub, then waiting for a user-defined sleep interval before doing it |
59 |
| -all over again. A few things are worth noting: |
60 |
| - |
61 |
| -1. The application is based upon the assumption that the SQL table is being updated by some |
62 |
| - external process, and you want to send all and only the updates to an Event Hub. |
63 |
| -2. The SQL table needs to have a field that has a unique and increasing number, for example, |
64 |
| - a record numer. This can be as simple as a field called "Id", or anything else that is |
65 |
| - incremented as whatever updates that database adds records such as "Creation_time" or "Sequence_number". The application notes and stores |
66 |
| - the value of that field in each iteration. In each subsequent pass through the loop, the |
67 |
| - application essentially queries the table for all records where the value of that field exceeds |
68 |
| - the value it saw the last time through the loop. We are calling this last value the "offset". |
69 |
| -3. The application creates a table "TableOffsets" when it starts up, to store the offsets. The |
70 |
| - table is created with the query "CreateOffsetTableQuery" defined in the config file. |
71 |
| -4. There are several queries used for working with the offset table, defined in the config |
72 |
| - file as "OffsetQuery", "UpdateOffsetQuery", and "InsertOffsetQuery". You should not change these. |
73 |
| -5. Finally, the query "DataQuery" defined in the config file is the query that will be run to |
74 |
| - pull the records from your SQL table. It is currently limited to the top 1,000 records in each pass |
75 |
| - through the loop for optimization purposes - if, for example, 25,000 records have been added |
76 |
| - to the database since the last query, it could take a while to execute the query. By limiting |
77 |
| - the query to 1,000 records each time, the queries are much faster. Selecting |
78 |
| - the top 1,000 simple pushes successive batches of 1,000 records to the event hub. |
79 |
| - |
80 |
| -## Next Steps |
81 |
| -To deploy the solution, clone or download the SqlToEventHub |
82 |
| -application, edit the App.config file, build it, and finally publish it. Once you have published the application, |
83 |
| -you can see it running in the Azure classic portal under Cloud Services, and monitor the events |
84 |
| -coming in to your event hub. Note that the frequency will be determined by two things: the |
85 |
| -frequency of the updates to the SQL table, and the sleep interval you have specified in the |
86 |
| -config file for the application. |
87 |
| - |
| 2 | +redirect_url: https://github.com/Azure-Samples/event-hubs-dotnet-import-from-sql |
| 3 | +--- |
0 commit comments