You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Quickstart: Create an app showing GitHub star count with Azure Functions and SignalR Service via C#
14
14
15
15
In this article, you'll learn how to use SignalR Service and Azure Functions to build a serverless application with C# to broadcast messages to clients.
16
16
17
+
# [In-process](#tab/in-process)
18
+
17
19
> [!NOTE]
18
20
> You can get the code mentioned in this article from [GitHub](https://github.com/aspnet/AzureSignalR-samples/tree/main/samples/QuickStartServerless/csharp).
19
21
22
+
# [Isolated process](#tab/isolated-process)
23
+
24
+
> [!NOTE]
25
+
> You can get the code mentioned in this article from [GitHub](https://github.com/aspnet/AzureSignalR-samples/tree/main/samples/QuickStartServerless/csharp-isolated).
26
+
27
+
---
28
+
20
29
## Prerequisites
21
30
22
31
The following prerequisites are needed for this quickstart:
@@ -37,6 +46,8 @@ You'll need the Azure Functions Core Tools for this step.
37
46
1. Create an empty directory and change to the directory with the command line.
38
47
1. Initialize a new project.
39
48
49
+
# [In-process](#tab/in-process)
50
+
40
51
```bash
41
52
# Initialize a function project
42
53
func init --worker-runtime dotnet
@@ -45,8 +56,22 @@ You'll need the Azure Functions Core Tools for this step.
var result = await response.Content.ReadFromJsonAsync<GitResult>();
202
+
if (result != null)
203
+
{
204
+
StarCount = result.StarCount;
205
+
}
206
+
}
207
+
return new SignalRMessageAction("newMessage", new object[] { $"Current star count of https://github.com/Azure/azure-signalr is: {StarCount}" });
208
+
}
209
+
210
+
private class GitResult
211
+
{
212
+
[JsonPropertyName("stargazers_count")]
213
+
public int StarCount { get;set; }
214
+
}
215
+
}
216
+
```
217
+
218
+
---
219
+
126
220
The code in*Function.cs* has three functions:
127
221
- `GetHomePage` is used to get a website as client.
128
222
- `Negotiate` is used by the client to get an access token.
@@ -166,6 +260,11 @@ You'll need the Azure Functions Core Tools for this step.
166
260
</ItemGroup>
167
261
```
168
262
263
+
1. Azure Functions requires a storage account to work. You can install and run the [Azure Storage Emulator](../storage/common/storage-use-azurite.md). **Or** you can update the setting to use your real storage account with the following command:
1. It's almost done now. The last step is to set a connection string of the SignalR Service to Azure Function settings.
170
269
171
270
1. Confirm the SignalR Service instance was successfully created by searching for its name in the search box at the top of the portal. Select the instance to open it.
@@ -188,11 +287,8 @@ You'll need the Azure Functions Core Tools for this step.
188
287
func start
189
288
```
190
289
191
-
After the Azure function is running locally, open `http://localhost:7071/api/index` and you can see the current star count. If you star or unstar in the GitHub, you'll get a star count refreshing every few seconds.
290
+
After the Azure function is running locally, open `http://localhost:7071/api/index`, and you can see the current star count. If you star or unstar in the GitHub, you'll get a star count refreshing every few seconds.
192
291
193
-
> [!NOTE]
194
-
> SignalR binding needs Azure Storage, but you can use a local storage emulator when the functionis running locally.
195
-
> If you got the error `There was an error performing a read operation on the Blob Storage Secret Repository. Please ensure the 'AzureWebJobsStorage' connection string is valid.` You need to download and enable [Storage Emulator](../storage/common/storage-use-emulator.md)
Copy file name to clipboardExpand all lines: articles/azure-signalr/signalr-quickstart-azure-functions-java.md
+20-22Lines changed: 20 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ In this article, you'll use Azure SignalR Service, Azure Functions, and Java to
22
22
- A code editor, such as [Visual Studio Code](https://code.visualstudio.com/)
23
23
- An Azure account with an active subscription. If you don't already have an account, [create an account for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio).
24
24
-[Azure Functions Core Tools](https://github.com/Azure/azure-functions-core-tools#installing). Used to run Azure Function apps locally.
25
-
25
+
26
26
- The required SignalR Service bindings in Java are only supported in Azure Function Core Tools version 2.4.419 (host version 2.0.12332) or above.
27
27
- To install extensions, Azure Functions Core Tools requires the [.NET Core SDK](https://dotnet.microsoft.com/download) installed. However, no knowledge of .NET is required to build Java Azure Function apps.
28
28
@@ -52,13 +52,13 @@ Make sure you have Azure Function Core Tools, Java (version 11 in the sample), a
52
52
|**groupId**|`com.signalr`| A value that uniquely identifies your project across all projects, following the [package naming rules](https://docs.oracle.com/javase/specs/jls/se6/html/packages.html#7.7) for Java. |
53
53
|**artifactId**|`java`| A value that is the name of the jar, without a version number. |
54
54
|**version**|`1.0-SNAPSHOT`| Choose the default value. |
55
-
|**package**|`com.signalr`| A value that is the Java package for the generated functioncode. Use the default. |
55
+
|**package**|`com.signalr`| A value that is the Java package for the generated functioncode. Use the default. |
56
56
57
57
1. Go to the folder `src/main/java/com/signalr` and copy the following code to *Function.java*:
1. Azure Functions requires a storage account to work. You can install and run the [Azure Storage Emulator](../storage/common/storage-use-azurite.md).
211
+
210
212
1. You're almost done now. The last step is to set a connection string of the SignalR Service to Azure Function settings.
211
213
212
214
1. Search for the Azure SignalR instance you deployed earlier using the **Search** box in Azure portal. Select the instance to open it.
@@ -234,10 +236,6 @@ Make sure you have Azure Function Core Tools, Java (version 11 in the sample), a
234
236
235
237
After Azure Function is running locally, go to `http://localhost:7071/api/index` and you'll see the current star count. If you star or "unstar" in the GitHub, you'll get a star count refreshing every few seconds.
236
238
237
-
> [!NOTE]
238
-
> SignalR binding needs Azure Storage, but you can use local storage emulator when the Function is running locally.
239
-
> If you got some error like `There was an error performing a read operation on the Blob Storage Secret Repository. Please ensure the 'AzureWebJobsStorage' connection string is valid.` You need to download and enable [Storage Emulator](../storage/common/storage-use-emulator.md)
0 commit comments