Code Monkey home page Code Monkey logo

azure-sql-db-serverless-geospatial-stream-analytics's Introduction

page_type languages products description urlFragment
sample
tsql
sql
csharp
azure-sql-database
azure-stream-analytics
azure
dotnet
dotnet-core
Monitor GeoFences in real-time using Azure SQL and Stream Analytics
azure-sql-db-serverless-geospatial-stream-analytics

Monitor GeoFences in real-time using Azure SQL and Stream Analytics

License

A fully working end-to-end solution, to process incoming real-time public transportation data by sending them to Event Hub and then processing the stream using Stream Analytics and Azure SQL.

Stream Analytics will read geofencing definition from Azure SQL and check if a bus is withing a defined geofence in real-time. The results will be then stored into Azure SQL for further processing and analysis.

How it works

The sample uses local console application to monitor Real-Time Public Transportation Data, available as GTFS-Realtime Feed and published by several public transportation companies like, for example, the King County Metro.

Every 15 seconds the application will wake up and get the GTFS Realtime Feed. It will send data to Event Hub, creating one event per Bus data. Stream Analytics will process the incoming stream, checking if a bus is within a Geofence (stored in dbo.GeoFences table and configured as a Reference Source Data).

Pre-Requisites

An Azure SQL database is needed. The database will not be created by the deployment script. If you need help to create an Azure SQL database, take a look here: Running the samples.

Create Database and import Route static data

The GTFS Realtime feed will give you data with some values that needs to be decoded like, for example, the RouteId. In order to transform such Id into something meaningful, like the Route name (eg. 221 Education Hill - Crossroads - Eastgate).

In an existing Azure SQL database, run the ./sql/00-create-obejcts.sql script to create needed tables.

You can download the static data zip file from here King County Metro GTFS Feed Zip File and then you can import it into the dbo.Routes table using the Import capabilities of SQL Server Management Studio, Azure Data Studio or just using BULK LOAD as in script ./sql/01-import-csv.sql

Deploy on Azure

The script ./azure-deploy.sh will take care of everything. Make sure you set the correct values for you subscription in the .env file for:

resourceGroup=""
storageName=""
location="" 
sqlServer=""
sqlDatabase=""
sqlUser=""
sqlPassword=""
eventhubsNamespace="azdbeh1"
storageAccount="azdbasa"

The script has been tested on Linux Ubuntu and the Windows Subsystem for Linux or the Cloud Shell.

The following resources will be created for you:

  • Azure Event Hubs
  • Azure Storage Account
  • Azure Stream Analytics

Run the GTFS to Event Hub application

To start to send data to Event Hubs, run the application in ./eh-gtfs folder. Before running the application make sure to create a ./eh-gtfs/.env file (from the provided template) and specify the correct value for the EventHubConnectionString setting. The value is the Event Hub namespace connection string. If you deployed the sample using the provided ./azure-deploy.sh script, such connection string is shown at the end of the script execution.

cd ./eh-gtfs
dotnet run

The application will connect to King County Metro public data feed and send it to Event Hubs to simulate a stream of geospatial data.

If you want something working 100% on Azure, without the need to run something locally, you can re-write the provided code as Azure Function or deploy the existing console application into an Azure Container Instance

Alternative Solution

An alterative solution, which also shows how to plot geospatial data on a map, can be found here:

https://github.com/Azure-Samples/azure-sql-db-serverless-geospatial

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

azure-sql-db-serverless-geospatial-stream-analytics's People

Contributors

microsoft-github-operations[bot] avatar microsoftopensource avatar yorek avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.