{"id":13850037,"url":"https://github.com/ealsur/serverlessnotifications","last_synced_at":"2025-03-22T12:33:21.809Z","repository":{"id":110731882,"uuid":"133080045","full_name":"ealsur/serverlessnotifications","owner":"ealsur","description":"Serverless notifications with Azure Cosmos DB + Azure Functions + Azure SignalR","archived":false,"fork":false,"pushed_at":"2018-05-25T14:23:04.000Z","size":127,"stargazers_count":61,"open_issues_count":1,"forks_count":17,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-08-05T20:30:00.657Z","etag":null,"topics":["azure","azure-cosmos-db","azure-functions","serverless","signalr"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ealsur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-05-11T19:22:54.000Z","updated_at":"2024-01-25T17:07:45.000Z","dependencies_parsed_at":"2023-04-24T16:31:52.619Z","dependency_job_id":null,"html_url":"https://github.com/ealsur/serverlessnotifications","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ealsur%2Fserverlessnotifications","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ealsur%2Fserverlessnotifications/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ealsur%2Fserverlessnotifications/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ealsur%2Fserverlessnotifications/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ealsur","download_url":"https://codeload.github.com/ealsur/serverlessnotifications/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221829695,"owners_count":16887663,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure","azure-cosmos-db","azure-functions","serverless","signalr"],"created_at":"2024-08-04T20:00:56.831Z","updated_at":"2024-10-28T12:54:42.401Z","avatar_url":"https://github.com/ealsur.png","language":"JavaScript","funding_links":[],"categories":["Azure Functions"],"sub_categories":[],"readme":"# Serverless notifications with Azure Cosmos DB + Azure Functions + Azure SignalR\n\nThis repo contains a reusable solution that creates a complete serverless scenario for a chat application that stores data in [Azure Cosmos DB](https://docs.microsoft.com/azure/cosmos-db/introduction), [Azure Functions](https://azure.microsoft.com/services/functions/) for hosting and event processing and [Azure SignalR](https://docs.microsoft.com/azure/azure-signalr/signalr-overview) for websocket client messaging.\n\nTo achieve complete serverless, this solution is using:\n\n* Azure Functions as a [serverless Web host](https://github.com/ealsur/serverlessnotifications/blob/master/src/function/ChangeFeedSignalR/Functions/FileServer.cs) for static html/js/css files (the chat client). \n* Azure Functions [HTTP API](https://github.com/ealsur/serverlessnotifications/blob/master/src/function/ChangeFeedSignalR/Functions/SaveChat.cs) to receive client calls to store data in Azure Cosmos DB using [Output bindings](https://docs.microsoft.com/azure/azure-functions/functions-bindings-cosmosdb#output).\n* Azure Functions [CosmosDB Trigger](https://github.com/ealsur/serverlessnotifications/blob/master/src/function/ChangeFeedSignalR/Functions/FeedToSignalR.cs) to send all generated chat lines to Azure SignalR.\n* The [web client](https://github.com/ealsur/serverlessnotifications/blob/master/src/function/ChangeFeedSignalR/www/index.html) is using [Azure SignalR's npm package](https://www.npmjs.com/package/@aspnet/signalr) for connectivity and transport protocol resolution.\n\n## How does it work?\n\nThe solution will provision one Azure Function App with multiple Functions. \n\n* [FileServer](https://github.com/ealsur/serverlessnotifications/blob/master/src/function/ChangeFeedSignalR/Functions/FileServer.cs): Acts as a serverless File server for static files that will let a Web client browse and obtain the files in the [www](https://github.com/ealsur/serverlessnotifications/tree/master/src/function/ChangeFeedSignalR/www) folder.\n* [SaveChat](https://github.com/ealsur/serverlessnotifications/blob/master/src/function/ChangeFeedSignalR/Functions/SaveChat.cs): Will receive data from the connected Web clients and save it to Azure Cosmos DB.\n* [SignalRConfiguration](https://github.com/ealsur/serverlessnotifications/blob/master/src/function/ChangeFeedSignalR/Functions/SignalRConfiguration.cs): Will send the required information to the Web client to initialize SignalR Websocket connection.\n* [FeedToSignalR](https://github.com/ealsur/serverlessnotifications/blob/master/src/function/ChangeFeedSignalR/Functions/FeedToSignalR.cs): Will trigger on new data in Azure Cosmos DB and broadcast it through Azure Signal R to all connected clients.\n\nIn order to support custom routes (particularly for the static Web host), it implements [Azure Functions Proxies](https://docs.microsoft.com/azure/azure-functions/functions-proxies) through a [proxies.json](https://github.com/ealsur/serverlessnotifications/blob/master/src/function/ChangeFeedSignalR/proxies.json) file. So when browsing the base URL, it is instead calling one of the HTTP triggered Functions.\n\n1. When the Web client loads the static resources, it pulls the SignalR configuration from [SignalRConfiguration](https://github.com/ealsur/serverlessnotifications/blob/master/src/function/ChangeFeedSignalR/Functions/SignalRConfiguration.cs).\n2. It will then negotiate with Azure SignalR the best transport protocol.\n![SignalR connections](./images/signalr.png)\n\n3. When the user writes a message, it will save it to Azure Cosmos DB via an Ajax call to [SaveChat](https://github.com/ealsur/serverlessnotifications/blob/master/src/function/ChangeFeedSignalR/Functions/SaveChat.cs)\n![Connected chat](./images/chat.png)\n\n4. Each chat line is stored as a Document in Azure Cosmos DB.\n![Stored document](./images/db.png)\n\n5. The [FeedToSignalR](https://github.com/ealsur/serverlessnotifications/blob/master/src/function/ChangeFeedSignalR/Functions/FeedToSignalR.cs) will trigger and broadcast it to all Azure SignalR connected clients.\n![Triggers](./images/invocation.png)\n\nThis solution does not create any server instance on your subscription, it runs completely on Azure Function's Consumption Plan and consumes Azure Cosmos DB as a serverless database and Azure SignalR as a serverless websocket notification service.\n\n## Requirements\n\n1. Have a pre-existing **Azure Cosmos DB** account to obtain the **Connection String**, the account needs to be a **SQL API account**. REMARKS: the format of the connection string should be \"Endpoint=https://{cosmosdb-name}.service.signalr.net;AccessKey={key};\".\n    1. Create a database called **chat** and a collection called **lines** (it can be the smallest possible 400RU collection).\n2. Have a pre-existing **Azure SignalR** account to obtain the **Connection String**.\n\n## How can I use this repo?\n\n### Run it locally\n\nClone this repo, fill out the [local.settings.json](https://github.com/ealsur/serverlessnotifications/blob/master/src/function/ChangeFeedSignalR/local.settings.json) file with the Connection Strings for Azure Cosmos DB and Azure SignalR and run it with F5!\n\nOpen your browser in the base address informed by the Azure Function's runtime (something along the lines of `http://localhost:\u003csome-port\u003e`).\n\n### Deploy it with one click\n\nJust click in the Deploy to **Azure button** and it will guide you into automatically creating the Azure Function app with all the code deployed on Azure.\n\n\u003ca href=\"https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fealsur%2Fserverlessnotifications%2Fmaster%2Fazuredeploy.json\" target=\"_blank\"\u003e\n    \u003cimg src=\"http://azuredeploy.net/deploybutton.png\"/\u003e\n\u003c/a\u003e\n\u003ca href=\"http://armviz.io/#/?load=https%3A%2F%2Fraw.githubusercontent.com%2Fealsur%2Fserverlessnotifications%2Fmaster%2Fazuredeploy.json\" target=\"_blank\"\u003e\n    \u003cimg src=\"http://armviz.io/visualizebutton.png\"/\u003e\n\u003c/a\u003e\n\nOpen your browser in the base address informed by the Azure Function's Portal (something along the lines of `https://\u003cyour-app-name\u003e.azurewebsites.net`).\n\n## Acknowledges\n\n* The web client code was based on Azure SignalR's [official samples repo](https://github.com/aspnet/AzureSignalR-samples/).\n* The Azure Function's static web server is based on [@anthonychu's sample](https://github.com/anthonychu/azure-functions-static-file-server).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fealsur%2Fserverlessnotifications","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fealsur%2Fserverlessnotifications","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fealsur%2Fserverlessnotifications/lists"}