Configure WebSocket Support

Objective

This document provides instructions on how to enable WebSocket-based communication for your application. WebSocket provides a persistent connection between client and server over HTTP or HTTPS.

Using the instructions provided in this guide, you can enable WebSocket connection for your services provisioned using an HTTP load balancer or virtual host. For more information, see Virtual Host.

Note: When configuring WebSocket support, it is recommended to use HTTP/1.1 for origin.


Prerequisites

The following prerequisites apply:


Configuration Sequence

You can use an HTTP load balancer or virtual host to configure WebSocket support for your application.

  • In case of HTTP load balancer, enabling WebSocket support is part of the HTTP load balancer configuration.

  • Enabling WebSocket-based communication in case of a virtual host requires performing the following sequence of actions:

PhaseDescription
Create Endpoint and ClusterCreate objects required for virtual host.
Create Route with WebSocketCreate route enabled for WebSocket communication.
Create Advertise Policy and Virtual HostCreate advertise policy and virtual host with the route and policy.

Note: You can enable WebSocket communication while creating the route, or you can edit an existing route to enable WebSocket support.


Configure WebSocket Using HTTP Load Balancer

Note: A server must not send a Transfer-Encoding header field in any response with a status code of 1xx (Informational) or 204 (No Content). A server must not send a Transfer-Encoding header field in any 2xx (Successful) response to a CONNECT request (Section 4.3.6 of RFC 7231).

Perform the following steps to create a route enabled with WebSocket support for an HTTP Load Balancer:

Step 1: Log into Console and go to HTTP load balancer settings.
  • From the Console homepage, click Multi-Cloud App Connect.
Figure
Figure: Console Homepage
  • Select a namespace.

  • Navigate to Manage > Load Balancers > HTTP Load Balancers.

  • Click ... for your load balancer and select Manage Configuration to open the load balancer configuration form.

  • Click Edit Configuration in the top right corner of the form.

Step 2: Start configuring routes.
  • In the Routes section, click Configure.

  • Click Add Item in the Routes page. This opens the route configuration form. By default, a simple route configuration loads.

  • Enter required fields, such as HTTP method, path match, and option associated to the path match selected (such as prefix, path, or regex).

  • Click Add item in Origin Pools section, select an origin pool from the Origin Pool menu, and then click Apply.

Figure
Figure: HTTP Load Balancer Simple Route
  • Scroll down and click Configure for the Advanced Options field. This opens the advanced route configuration options.

  • Scroll down to the Protocol Upgrades section and click on the Enable/Disable Websocket Upgrade menu, and then select the Enable WebSocket option.

Figure
Figure: Load Balancer WebSocket Configuration
  • Enable the Use Websocket option.

  • Scroll down and click Apply.

Step 3: Enable WebSocket communication.
  • Click Apply in the simple route page.

  • Click Apply in the routes list page.

  • Click Save and Exit in the load balancer configuration form.


Configure WebSocket Using Virtual Host

Note: A server must not send a Transfer-Encoding header field in any response with a status code of 1xx (Informational) or 204 (No Content). A server must not send a Transfer-Encoding header field in any 2xx (Successful) response to a CONNECT request (Section 4.3.6 of RFC 7231).

Create Endpoint and Cluster

F5 Distributed Cloud virtual host requires an endpoint and associated cluster where the service is available or discovered. For instructions on creating endpoint and cluster, see Create Endpoint and Create Cluster, respectively.

Create Route with WebSocket

Perform the following steps to create a route enabled with WebSocket support.

Step 1: Navigate to the routes page.
  • Select the Multi-Cloud App Connect service.

  • Select the desired namespace from the Namespace drop-down menu.

  • Navigate to Manage > Virtual Host > Routes.

Figure
Figure Cloud Credentials
Step 2: Add a route.
  • Click Add Route.

  • Enter a name for the route. Optionally, set labels and add a description.

  • In the List of routes section, click Configure.

  • Click Add Item to add a new route to the list.

  • In the Actions section, make sure Destination List is set as the action, and then click Configure.

Step 3: Set the destination origin pools (clusters).
  • In the Destination Origin pools (clusters) list and under the Origin Pools and Weights section, click Add Item.

  • Select an existing cluster from the Cluster drop-down list, or click the create a new cluster at the bottom of the drop-down list.

  • From the Cluster menu, select a cluster object.

  • In the Weight field, enter a weight for this cluster if multiple clusters are needed.

  • Click Apply to apply the cluster to the destination list.

Figure
Route Destination Cluster Configuration
Step 4: Configure the destination actions.
  • In the Destination Actions section, enable the Show Advanced Fields option.

  • In the Websocket Configuration section, click Configure.

  • Check the Use Websocket checkbox and click Apply.

  • Optionally, enter a value in milliseconds in the Timeout field. The WebSocket connection gets closed after the set time period of idle time.

  • Optionally, configure the Retry Policy policy. The default is one retry, with no conditions or changes:

    • Click Configure.

    • From the Condition Retry menu, select the condition under which the retry policy will trigger. Click Add Item to add multiple conditions.

    • From the Number of Retries menu, select the number of retry attempts to perform.

    • Optionally, configure the Per Try Timeout, Base Retry Interval, and Maximum Retry Interval options.

    • Click Apply.

Figure
Figure: WebSocket Configuration Option in Route
Step 5: Complete the route.
  • Click Apply to save the destination list.

  • Click Apply to save the actions.

  • Click Apply to save the list of routes.

  • Click Save and Exit to save the route.

Note: Configure all the other fields as necessary. For information on all fields, see the Create Route section.

Create Advertise Policy and Virtual Host

Distributed Cloud virtual host requires an advertise policy to specify where and how the service is advertised.

Step 1: Create an advertise policy.
Step 2: Create a virtual host of type HTTP Proxy or HTTPS Proxy.
  • Create a virtual host of type HTTP Proxy or HTTPS Proxy. Use the instructions in the Create Advertise Policy chapter of Create and Advertise a Virtual Host guide.

  • Apply the route created in the Create Route with WebSocket chapter.


Concepts


API References