Skip to content

Latest commit

 

History

History
86 lines (54 loc) · 3.95 KB

signalr-quickstart-azure-functions-java.md

File metadata and controls

86 lines (54 loc) · 3.95 KB
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

Quickstart: Use Java to create a chat room with Azure Functions and SignalR Service

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.

Prerequisites

  • 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.

Log in to Azure

Sign in to the Azure portal at https://portal.azure.com/ with your Azure account.

[!INCLUDE Create instance]

[!INCLUDE Clone application]

Configure and run the Azure Function app

  1. 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.

    Search for the SignalR Service instance

  2. Select Keys to view the connection strings for the SignalR Service instance.

  3. Select and copy the primary connection string.

    Create SignalR Service

  4. In your code editor, open the src/chat/java folder in the cloned repository.

  5. Rename local.settings.sample.json to local.settings.json.

  6. In local.settings.json, paste the connection string into the value of the AzureSignalRConnectionString setting. Save the file.

  7. 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.
  8. In the terminal, ensure that you are in the src/chat/java folder. Build the function app.

    mvn clean package
  9. Run the function app locally.

    mvn azure-functions:run

[!INCLUDE Run web application]

[!INCLUDE Cleanup]

Next steps

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