-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1560 from Thushani-Jayasekera/dev
Add documentation for WebSocket Endpoints
- Loading branch information
Showing
8 changed files
with
176 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...components/develop-services/expose-a-nodejs-websocket-endpoint-via-a-service.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# Expose a NodeJS WebSocket Endpoint via a Service | ||
|
||
Choreo allows you to create and deploy applications in your preferred programming language, offering a seamless platform for building dynamic and scalable solutions. This guide walks you through the steps to deploy a WebSocket service using the NodeJS buildpack. | ||
|
||
WebSockets provide real-time, two-way communication between a client and server over a persistent TCP connection. This makes WebSocket APIs ideal for applications that require real-time updates. | ||
|
||
In this guide, you will: | ||
|
||
- Build a simple WebSocket service using a sample implementation in NodeJS. | ||
- Deploy the service in Choreo, allowing any WebSocket client application to establish a connection and exchange real-time messages with your service. | ||
|
||
## Prerequisites | ||
|
||
- If you are signing in to the Choreo Console for the first time, create an organization as follows: | ||
|
||
1. Go to [https://console.choreo.dev/](https://console.choreo.dev/), and sign in using your preferred method. | ||
2. Enter a unique organization name. For example, `Stark Industries`. | ||
3. Read and accept the privacy policy and terms of use. | ||
4. Click **Create**. | ||
|
||
This creates the organization and opens the **Project Home** page of the default project created for you. | ||
|
||
- Fork the [Choreo samples repository](https://github.com/wso2/choreo-samples/), which contains the [sample WebSocket service](https://github.com/wso2/choreo-samples/tree/main/websocket-chat-app) implementation for this guide. | ||
|
||
Let's get started! | ||
|
||
## Learn the repository file structure | ||
|
||
It is important to understand the purpose of the key files in the sample service. The following table provides a brief overview of each file in the NodeJS chat Application. | ||
|
||
!!! note | ||
The following file paths are relative to the path `<sample-repository-dir>/websocket-chat-app/websocket-chat-service-nodejs`. | ||
|
||
|Filepath | Description | | ||
|--------------------------------|-----------------------------------------------------------------| | ||
| `server.js` | The NodeJS chat service. | | ||
| `.choreo/component-config.yaml`| The configuration file with endpoint details. | | ||
|
||
## Step 1: Create a service component | ||
|
||
To create a NodeJS service component, follow these steps: | ||
|
||
1. Go to [https://console.choreo.dev/](https://console.choreo.dev/) and sign in. This opens the project home page. | ||
2. If you already have one or more components in your project, click **+ Create**. Otherwise, proceed to the next step. | ||
3. Click the **Service** card. | ||
4. Enter a display name, a unique name, and a description for the service component. You can enter the values given below: | ||
|
||
!!! info | ||
In the **Component Name** field, you must specify a name to uniquely identify the component in various contexts. The value is editable only at the time you create the component. You cannot change the name after you create the component. | ||
|
||
| **Field** | **Value** | | ||
|---------------------------|-------------------------| | ||
| **Component Display Name**| `NodeJS Chat Service` | | ||
| **Component Name** | `nodejs-chat-service` | | ||
| **Description** | Manage a chat service | | ||
|
||
5. Click the **GitHub** tab. | ||
6. To allow Choreo to connect to your GitHub account, click **Authorize with GitHub**. If you have not already connected your GitHub repository to Choreo, enter your GitHub credentials and select the repository you created in the prerequisites section to install the [Choreo GitHub App](https://github.com/marketplace/choreo-apps). | ||
|
||
Alternatively, you can paste the [Choreo samples repository](https://github.com/wso2/choreo-samples) URL in the **Provide Repository URL** field to connect to it without requiring authorization from the [Choreo Apps](https://github.com/marketplace/choreo-apps) GitHub application. However, authorizing the repository with the [Choreo GitHub App](https://github.com/marketplace/choreo-apps) is necessary if you want to enable [**Auto Deploy**](https://wso2.com/choreo/docs/choreo-concepts/ci-cd/#deploy) for the component. | ||
|
||
!!! note | ||
The **Choreo GitHub App** requires the following permissions: | ||
|
||
- Read and write access to code and pull requests. | ||
- Read access to issues and metadata. | ||
You can [revoke access](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/reviewing-your-authorized-integrations#reviewing-your-authorized-github-apps) if you do not want Choreo to have access to your GitHub account. However, write access is exclusively utilized for sending pull requests to a user repository. Choreo will not directly push any changes to a repository. | ||
|
||
7. Under **Connect Your Repository**, enter the following information: | ||
|
||
| **Field** | **Value** | | ||
|-------------------------|-------------------------| | ||
| **Organization** | Your GitHub account | | ||
| **GitHub Repository** | **`choreo-samples`** | | ||
| **Branch** | **`main`** | | ||
|
||
8. Select **NodeJS** as the buildpack. | ||
9. Enter the following information: | ||
|
||
| **Field** | **Value** | | ||
|--------------------------------|-----------------------------------------------------| | ||
| **NodeJS Project Directory** | `websocket-chat-app/websocket-chat-service-nodejs` | | ||
|
||
10. Click **Create**. This creates the component and takes you to the **Overview** page of the component. | ||
|
||
You have successfully created a service component that provides a WebSocket API built with NodeJS. The next step is to proceed with building and deploying the service. | ||
|
||
## Step 2: Build and deploy | ||
|
||
Now that you have connected the source repository, it's time to build and deploy the chat service. | ||
|
||
### Step 2.1: Build | ||
|
||
To build the service, follow these steps: | ||
|
||
1. In the left navigation menu, click **Build**. | ||
2. On the **Build** page, click **Build Latest**. | ||
|
||
!!! note | ||
Building the service component may take a while. You can track the progress via the logs in the **Build Details** pane. Once the build process is complete, the build status changes to **Success**. | ||
|
||
### Step 2.2: Deploy | ||
|
||
To deploy the service, follow these steps: | ||
|
||
1. In the left navigation menu, click **Deploy**. | ||
2. On the **Set Up** card, click **Configure & Deploy**. | ||
3. In the **Configurations** pane that opens, click **Next** to skip the configuration. | ||
4. Review the **Endpoint Details** and click **Deploy**. | ||
|
||
!!! note | ||
Deploying the service component may take a while. Once deployed, the **Development** environment card indicates the **Deployment Status** as **Active**. | ||
|
||
Once you have successfully deployed your service, you can [test](../../testing/test-websocket-endpoints-via-the-websocket-console.md), [manage](../../api-management/lifecycle-management.md), and observe it like any other component type in Choreo. | ||
|
||
!!! note | ||
Some clients, such as certain browsers, may not support adding headers to the WebSocket handshake. In these cases, you can include the access token or API key required for WebSocket API invocation within the `sec-websocket-protocolheader`, along with any specified subprotocols. | ||
|
||
For example: `sec-websocket-protocol: choreo-oauth2-key, {access token}, subprotocols` | ||
|
||
If you are using an API key, replace `choreo-oauth2-key` with `choreo-internal-API-key`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
en/docs/testing/test-websocket-endpoints-via-the-websocket-console.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Test WebSocket Endpoints via the WebSocket Console | ||
|
||
Choreo provides an integrated WebSocket Console to test publicly exposed WebSocket endpoints of Service components you create and deploy. The WebSocket Console allows you to connect to your service and exchange messages interactively. Choreo secures WebSocket APIs with OAuth2.0 by default, and the console automatically generates test keys for authenticated API testing. | ||
|
||
Follow the steps below to test a WebSocket endpoint via the WebSocket Console: | ||
|
||
1. Sign in to the [Choreo Console](https://console.choreo.dev/). | ||
|
||
2. In the **Component Listing** pane, click on the component you want to test. | ||
|
||
3. Click **Test** in the left navigation menu and then click **Console**. This opens the **WebSocket Console** pane. | ||
|
||
4. In the **WebSocket Console** pane, select the environment from the drop-down list. | ||
|
||
5. Select the required endpoint from the **Endpoint** list. | ||
|
||
!!! note | ||
- The **Network Visibility** of an endpoint is set in the **endpoints.yaml** file. You can set it to **Public**, **Organization**, or **Project**. | ||
- If you have set the **Network Visibility** of the endpoint to **Public**, proceed to step 7. | ||
- If you have set the **Network Visibility** of the endpoint to **Organization**, it won't be accessible from outside the organization. For testing, Choreo allows you to generate a temporary URL that remains active for 15 minutes. Follow step 6 to generate the URL. | ||
|
||
6. If the **Network Visibility** of the endpoint is set to **Organization**, click **Generate URL** to generate a temporary test URL valid for 15 minutes. Otherwise, skip this step. | ||
|
||
!!! note | ||
The temporary test URL is valid for 15 minutes and will expire after that. If you want to manually deactivate it, click **Deactivate URL**. | ||
|
||
![WebSocket Console](../assets/img/testing/websocket-console.png){.cInlineImage-full} | ||
|
||
7. Expand the channel you want to test. | ||
|
||
8. Click **Connect** to establish a connection. The connection status will be displayed in the output logs. | ||
|
||
9. Send and receive messages to and from the deployed service. | ||
|
||
!!! note | ||
The maximum connection duration is 15 minutes. After that, the connection terminates. To reconnect, click **Connect** again. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters