title | description | author | ms.service | ms.devlang | ms.topic | ms.date | ms.author |
---|---|---|---|---|---|---|---|
Use Java to create a chat room with Azure Functions and SignalR Service |
A quickstart for using Azure SignalR Service and Azure Functions to create a chat room. |
sffamily |
signalr |
java |
quickstart |
03/04/2019 |
zhshang |
Azure SignalR Service lets you easily add real-time functionality to your application and Azure Functions is a serverless platform that lets you run your code without managing any infrastructure. In this quickstart, you use Java to build a serverless, real-time chat application using SignalR Service and Functions.
-
A code editor, such as Visual Studio Code
-
An Azure account with an active subscription. Create an account for free.
-
Azure Functions Core Tools. Used to run Azure Function apps locally.
[!NOTE] 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.
[!NOTE] To install extensions, Azure Functions Core Tools requires the .NET Core SDK installed. However, no knowledge of .NET is required to build JavaScript Azure Function apps.
-
Java Developer Kit, version 8
-
Apache Maven, version 3.0 or above
Note
This quickstart can be run on macOS, Windows, or Linux.
Sign in to the Azure portal at https://portal.azure.com/ with your Azure account.
[!INCLUDE Create instance]
[!INCLUDE Clone application]
-
In the browser where the Azure portal is opened, confirm the SignalR Service instance you deployed earlier was successfully created by searching for its name in the search box at the top of the portal. Select the instance to open it.
-
Select Keys to view the connection strings for the SignalR Service instance.
-
Select and copy the primary connection string.
-
In your code editor, open the src/chat/java folder in the cloned repository.
-
Rename local.settings.sample.json to local.settings.json.
-
In local.settings.json, paste the connection string into the value of the AzureSignalRConnectionString setting. Save the file.
-
The main file that contains the functions are in src/chat/java/src/main/java/com/function/Functions.java:
- negotiate - Uses the SignalRConnectionInfo input binding to generate and return valid connection information.
- sendMessage - Receives a chat message in the request body and uses the SignalR output binding to broadcast the message to all connected client applications.
-
In the terminal, ensure that you are in the src/chat/java folder. Build the function app.
mvn clean package
-
Run the function app locally.
mvn azure-functions:run
[!INCLUDE Run web application]
[!INCLUDE Cleanup]
In this quickstart, you built and ran a real-time serverless application using Maven. Next, learn about how to create Java Azure Functions from scratch.
[!div class="nextstepaction"] Create your first function with Java and Maven