Skip to content

Commit

Permalink
Merge pull request #121 from Azure/dev
Browse files Browse the repository at this point in the history
Release 1.2.0
  • Loading branch information
zackliu committed Jun 1, 2020
2 parents c734ac3 + c6ab0dd commit 224c107
Show file tree
Hide file tree
Showing 104 changed files with 6,454 additions and 73 deletions.
49 changes: 47 additions & 2 deletions azure-functions-signalrservice-extension.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.29806.167
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{7005F387-A2ED-42B0-8CE1-41639A6D1E51}"
EndProject
Expand All @@ -22,6 +22,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
version.props = version.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.SignalR.Serverless.Protocols", "src\Microsoft.Azure.SignalR.Serverless.Protocols\Microsoft.Azure.SignalR.Serverless.Protocols.csproj", "{B6468EC0-E62B-4037-BB77-461DB3AB6F20}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.SignalR.Serverless.Protocols.Tests", "test\Microsoft.Azure.SignalR.Serverless.Protocols.Tests\Microsoft.Azure.SignalR.Serverless.Protocols.Tests.csproj", "{E796842E-4BE7-48F2-8C77-89B42AE065DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Azure.WebJobs.Extensions.SignalRService.Tests.Common", "test\Microsoft.Azure.WebJobs.Extensions.SignalRService.Tests.Common\Microsoft.Azure.WebJobs.Extensions.SignalRService.Tests.Common.csproj", "{BACA8231-3939-4340-B405-CA681DB4C89B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -56,13 +62,52 @@ Global
{CFFE1AEB-0D5A-458E-AA45-8F312B1F37F3}.Release|x64.Build.0 = Release|Any CPU
{CFFE1AEB-0D5A-458E-AA45-8F312B1F37F3}.Release|x86.ActiveCfg = Release|Any CPU
{CFFE1AEB-0D5A-458E-AA45-8F312B1F37F3}.Release|x86.Build.0 = Release|Any CPU
{B6468EC0-E62B-4037-BB77-461DB3AB6F20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6468EC0-E62B-4037-BB77-461DB3AB6F20}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6468EC0-E62B-4037-BB77-461DB3AB6F20}.Debug|x64.ActiveCfg = Debug|Any CPU
{B6468EC0-E62B-4037-BB77-461DB3AB6F20}.Debug|x64.Build.0 = Debug|Any CPU
{B6468EC0-E62B-4037-BB77-461DB3AB6F20}.Debug|x86.ActiveCfg = Debug|Any CPU
{B6468EC0-E62B-4037-BB77-461DB3AB6F20}.Debug|x86.Build.0 = Debug|Any CPU
{B6468EC0-E62B-4037-BB77-461DB3AB6F20}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6468EC0-E62B-4037-BB77-461DB3AB6F20}.Release|Any CPU.Build.0 = Release|Any CPU
{B6468EC0-E62B-4037-BB77-461DB3AB6F20}.Release|x64.ActiveCfg = Release|Any CPU
{B6468EC0-E62B-4037-BB77-461DB3AB6F20}.Release|x64.Build.0 = Release|Any CPU
{B6468EC0-E62B-4037-BB77-461DB3AB6F20}.Release|x86.ActiveCfg = Release|Any CPU
{B6468EC0-E62B-4037-BB77-461DB3AB6F20}.Release|x86.Build.0 = Release|Any CPU
{E796842E-4BE7-48F2-8C77-89B42AE065DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E796842E-4BE7-48F2-8C77-89B42AE065DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E796842E-4BE7-48F2-8C77-89B42AE065DB}.Debug|x64.ActiveCfg = Debug|Any CPU
{E796842E-4BE7-48F2-8C77-89B42AE065DB}.Debug|x64.Build.0 = Debug|Any CPU
{E796842E-4BE7-48F2-8C77-89B42AE065DB}.Debug|x86.ActiveCfg = Debug|Any CPU
{E796842E-4BE7-48F2-8C77-89B42AE065DB}.Debug|x86.Build.0 = Debug|Any CPU
{E796842E-4BE7-48F2-8C77-89B42AE065DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E796842E-4BE7-48F2-8C77-89B42AE065DB}.Release|Any CPU.Build.0 = Release|Any CPU
{E796842E-4BE7-48F2-8C77-89B42AE065DB}.Release|x64.ActiveCfg = Release|Any CPU
{E796842E-4BE7-48F2-8C77-89B42AE065DB}.Release|x64.Build.0 = Release|Any CPU
{E796842E-4BE7-48F2-8C77-89B42AE065DB}.Release|x86.ActiveCfg = Release|Any CPU
{E796842E-4BE7-48F2-8C77-89B42AE065DB}.Release|x86.Build.0 = Release|Any CPU
{BACA8231-3939-4340-B405-CA681DB4C89B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BACA8231-3939-4340-B405-CA681DB4C89B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BACA8231-3939-4340-B405-CA681DB4C89B}.Debug|x64.ActiveCfg = Debug|Any CPU
{BACA8231-3939-4340-B405-CA681DB4C89B}.Debug|x64.Build.0 = Debug|Any CPU
{BACA8231-3939-4340-B405-CA681DB4C89B}.Debug|x86.ActiveCfg = Debug|Any CPU
{BACA8231-3939-4340-B405-CA681DB4C89B}.Debug|x86.Build.0 = Debug|Any CPU
{BACA8231-3939-4340-B405-CA681DB4C89B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BACA8231-3939-4340-B405-CA681DB4C89B}.Release|Any CPU.Build.0 = Release|Any CPU
{BACA8231-3939-4340-B405-CA681DB4C89B}.Release|x64.ActiveCfg = Release|Any CPU
{BACA8231-3939-4340-B405-CA681DB4C89B}.Release|x64.Build.0 = Release|Any CPU
{BACA8231-3939-4340-B405-CA681DB4C89B}.Release|x86.ActiveCfg = Release|Any CPU
{BACA8231-3939-4340-B405-CA681DB4C89B}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{27EBF417-718B-40A2-808B-EF6538AEEDC7} = {7005F387-A2ED-42B0-8CE1-41639A6D1E51}
{CFFE1AEB-0D5A-458E-AA45-8F312B1F37F3} = {D6082274-DF4A-455D-9EF3-090C74BC96A1}
{B6468EC0-E62B-4037-BB77-461DB3AB6F20} = {7005F387-A2ED-42B0-8CE1-41639A6D1E51}
{E796842E-4BE7-48F2-8C77-89B42AE065DB} = {D6082274-DF4A-455D-9EF3-090C74BC96A1}
{BACA8231-3939-4340-B405-CA681DB4C89B} = {D6082274-DF4A-455D-9EF3-090C74BC96A1}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {227AD9AE-1447-4D8C-A014-50ABEC8E005C}
Expand Down
7 changes: 6 additions & 1 deletion build/dependencies.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
<PropertyGroup Label="Package Versions">
<MicroBuildCorePackageVersion>0.3.0</MicroBuildCorePackageVersion>
<MicrosoftAzureSignalRManagement>1.4.1</MicrosoftAzureSignalRManagement>
<MicrosoftAzureWebJobsPackageVersion>3.0.4</MicrosoftAzureWebJobsPackageVersion>
<MicrosoftAzureFunctionsExtensionsVersion>1.0.0</MicrosoftAzureFunctionsExtensionsVersion>
<MicrosoftNETTestSdkPackageVersion>15.8.0</MicrosoftNETTestSdkPackageVersion>
<MoqPackageVersion>4.9.0</MoqPackageVersion>
<XunitPackageVersion>2.4.0</XunitPackageVersion>
<XunitRunnerVisualstudioPackageVersion>2.4.0</XunitRunnerVisualstudioPackageVersion>
<MessagePackPackageVersion>1.9.11</MessagePackPackageVersion>
<NewtonsoftJsonPackageVersion>11.0.2</NewtonsoftJsonPackageVersion>
<SystemMemoryPackageVersion>4.5.3</SystemMemoryPackageVersion>
<MicrosoftAspNetCoreSignalRProtocolsMessagePackPackageVersion>1.1.5</MicrosoftAspNetCoreSignalRProtocolsMessagePackPackageVersion>

</PropertyGroup>
<Import Project="$(DotNetPackageVersionPropsPath)" Condition=" '$(DotNetPackageVersionPropsPath)' != '' " />
</Project>
116 changes: 116 additions & 0 deletions samples/bidirectional-chat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Azure function bidirectional chatroom sample

This is a chatroom sample that demonstrates bidirectional message pushing between Azure SignalR Service and Azure Function in serverless scenario. It leverages the **upstream** provided by Azure SignalR Service that features proxying messages from client to upstream endpoints in serverless scenario. Azure Functions with SignalR trigger binding allows you to write code to receive and push messages in several languages, including JavaScript, Python, C#, etc.

- [Prerequisites](#prerequisites)
- [Run sample in Azure](#run-sample-in-azure)

<a name="prerequisites"></a>

## Prerequisites

The following softwares are required to build this tutorial.
* [.NET SDK](https://dotnet.microsoft.com/download) (Version 3.1, required for Functions extensions)
* [Azure Functions Core Tools](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash#install-the-azure-functions-core-tools) (Version 3)
* [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)

<a name="run-sample-in-azure"></a>

## Run sample in Azure

It's a quick try of this sample. You will create an Azure SignalR Service and an Azure Function app to host sample. And you will launch chatroom locally but connecting to Azure SignalR Service and Azure Function.

### Create Azure SignalR Service

1. Create Azure SignalR Service using `az cli`

```bash
az signalr create -n <signalr-name> -g <resource-group-name> --service-mode Serverless --sku Free_F1
```

For more details about creating Azure SignalR Service, see the [tutorial](https://docs.microsoft.com/en-us/azure/azure-signalr/signalr-quickstart-azure-functions-javascript#create-an-azure-signalr-service-instance).

### Deploy project to Azure Function

1. Deploy with Azure Functions Core Tools
1. [Install Azure Functions Core Tools](https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash#install-the-azure-functions-core-tools)
2. [Create Azure Function App](https://docs.microsoft.com/en-us/azure/azure-functions/scripts/functions-cli-create-serverless#sample-script) (code snippet shown below)

```bash
#!/bin/bash

# Function app and storage account names must be unique.
storageName=mystorageaccount$RANDOM
functionAppName=myserverlessfunc$RANDOM
region=westeurope

# Create a resource group.
az group create --name myResourceGroup --location $region

# Create an Azure storage account in the resource group.
az storage account create \
--name $storageName \
--location $region \
--resource-group myResourceGroup \
--sku Standard_LRS

# Create a serverless function app in the resource group.
az functionapp create \
--name $functionAppName \
--storage-account $storageName \
--consumption-plan-location $region \
--resource-group myResourceGroup \
--functions-version 3
```

3. Renaming `local.settings.sample.json` to `local.settings.json`
4. Publish the sample to the Azure Function you created before.

```bash
cd <root>/bidirectional-chat/csharp
// If prompted function app version, use --force
func azure functionapp publish <function-app-name>
```

2. Update application settings

```bash
az functionapp config appsettings set --resource-group <resource_group_name> --name <function_name> --setting AzureSignalRConnectionString="<signalr_connection_string>"
```

3. Update Azure SignalR Service Upstream settings

Open the Azure Portal and nevigate to the Function App created before. Find `signalr_extension` key in the **App keys** blade.

![Overview with auth](getkeys.png)

Copy the `signalr_extensions` value and use `az resource` command to set the upstream setting.

```bash
az resource update --ids <signalr-resource-id> --set properties.upstream.templates="[{'UrlTemplate': '<function-url>/runtime/webhooks/signalr?code=<signalr_extension-key>', 'EventPattern': '*', 'HubPattern': '*', 'CategoryPattern': '*'}]"
```

### Use a chat sample website to test end to end

1. Enable function app cross origin resource sharing (CORS)

Although there is a CORS setting in local.settings.json, it is not propagated to the function app in Azure. You need to set it separately.

1. Open the function app in the Azure Portal.
2. In the left blade, select **CORS** blade.
3. In the **Allowed Origins** section, add `http://127.0.0.1:5500` (It is the local web server's url).
4. In order for the SignalR JavaScript SDK call your function app from a browser, support for credentials in CORS must be enabled. Select the **Enable Access-Control-Allow-Credentials** checkbox.
5. Click **Save** to persist the CORS settings.
![CORS](cors.png)

2. Install [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) for your VS Code, that can serve web pages locally
3. Open `bidirectional-chat/content/index.html` and edit base url

```js
window.apiBaseUrl = '<function-app-url>';
```

4. With **index.html** open, start Live Server by opening the VS Code command palette (**F1**) and selecting **Live Server: Open with Live Server**. Live Server will open the application in a browser.

5. Try send messages by entering them into the main chat box.
![Chatroom](chatroom.png)
Binary file added samples/bidirectional-chat/chatroom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 224c107

Please sign in to comment.