Creates a TCP listener.

Note Newly created listeners are in the Stopped state. After a listener is created, you must call the StartLoadBalancerListener operation to start the listener to forward traffic.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes CreateLoadBalancerTCPListener

The operation that you want to perform.

Set the value to CreateLoadBalancerTCPListener.

Bandwidth Integer Yes -1

The maximum bandwidth value of the listener. Valid values: -1 and 1 to 5120.

-1: For a pay-by-data-transfer Internet-facing SLB instance, you can set the value to -1. This indicates that the bandwidth is unlimited.

1 to 5120: For a pay-by-bandwidth Internet-facing SLB instance, you can specify a bandwidth cap for each listener. The sum of maximum bandwidth values that you set for all listeners cannot exceed the maximum bandwidth value of the SLB instance.

ListenerPort Integer Yes 80

The frontend port that is used by the SLB instance.

Valid values: 1 to 65535.

LoadBalancerId String Yes lb-bp1b6c719dfa08ex****

The ID of the SLB instance.

RegionId String Yes cn-hangzhou

The region where the SLB instance is created.

You can query the most recent region list from the Regions and zones list or by calling the DescribeRegions operation.

BackendServerPort Integer No 80

The backend port that is used by the SLB instance.

Valid values: 1 to 65535.

If the VServerGroupId parameter is not set, this parameter is required.

Scheduler String No wrr

The scheduling algorithm. Valid values:

  • wrr (default): Backend servers that have higher weights receive more requests than those that have lower weights.
  • rr: Requests are sequentially distributed to backend servers.
  • sch: specifies consistent hashing that is based on source IP addresses. Requests from the same source IP address are distributed to the same backend server.
  • tch: specifies consistent hashing that is based on four factors: source IP address, destination IP address, source port number, and destination port number. Requests that contain the same preceding information are distributed to the same backend server.
Note Only guaranteed-performance SLB instances support sch and tch.

The consistent hashing (CH) algorithm is supported in the following regions:

  • Japan (Tokyo)
  • India (Mumbai)
  • Singapore Zone B and Singapore Zone C
  • Australia (Sydney)
  • Malaysia (Kuala Lumpur)
  • Indonesia (Jakarta)
  • Germany (Frankfurt)
  • UK (London)
  • UAE (Dubai)
  • US (Silicon Valley)
  • US (Virginia)
  • Hongkong Zone B and Hongkong Zone C
  • Beijing Zone C, Beijing Zone D, Beijing Zone E, Beijing Zone F, Beijing Zone G, and Beijing Zone H.
  • Chengdu Zone A
  • Hangzhou Zone B, Hangzhou Zone C, Hangzhou Zone E, Hangzhou Zone F, Hangzhou Zone I, and Hangzhou Zone H
  • China (Hohhot)
  • Qingdao Zone B and Qingdao Zone C
  • Shanghai Zone B, Shanghai Zone D, Shanghai Zone E, Shanghai Zone F, Shanghai Zone G, Shanghai Zone H, and Shanghai Zone J.
  • Shenzhen Zone B, Shenzhen Zone C, Shenzhen Zone D, and Shenzhen Zone E.
  • Zhangjiakou Zone A and Zhangjiakou Zone B
PersistenceTimeout Integer No 0

The timeout period of session persistence.

Valid values: 0 to 3600. Unit: seconds.

Default value: 0. This indicates that session persistence is disabled.

EstablishedTimeout Integer No 500

The timeout period of connections.

Valid values: 10 to 900. Unit: seconds.

HealthyThreshold Integer No 4

The number of consecutive successful health checks that must occur before an unhealthy backend server is declared healthy. In this case, the health check state is changed from fail to success.

Valid values: 2 to 10.

UnhealthyThreshold Integer No 4

The number of consecutive failed health checks that must occur before a healthy backend server is declared unhealthy. In this case, the health check state is changed from success to fail.

Valid values: 2 to 10.

HealthCheckConnectTimeout Integer No 100

The timeout period of a health check.

Valid values: 1 to 300. Unit: seconds.

Default value: 5.

HealthCheckConnectPort Integer No 80

The port that is used for health checks.

Valid values: 1 to 65535.

If this parameter is not set, the port specified by BackendServerPort is used for health checks.

healthCheckInterval Integer No 3

The time interval between two consecutive health checks.

Valid values: 1 to 50. Unit: seconds.

HealthCheckDomain String No 172.XX.XX.6

The domain name that is used for health checks. Valid values:

  • $_ip: The private IP address of the backend server. If the $_ip parameter is set or the HealthCheckDomain parameter is not set, SLB uses the private IP addresses of backend servers as the domain names for health checks.
  • domain: The domain name must be 1 to 80 characters in length, and can contain only letters, digits, periods (.),and hyphens (-).
HealthCheckURI String No /test/index.html

The URI that is used for health checks. The URI must be 1 to 80 characters in length, and can contain letters, digits, hyphens (-), forward slashes (/), periods (.), percent signs (%), number signs (#), and ampersands (&). The URI must start with a forward slash (/) but cannot be a single forward slash (/).

You can set this parameter when the TCP listener requires HTTP health checks. If you do not set this parameter, TCP health checks are performed.

HealthCheckHttpCode String No http_2xx,http_3xx

The HTTP status code that indicates a successful health check. Separate multiple HTTP status codes with commas (,).

Valid values:

  • http_2xx(default value)
  • http_3xx
  • http_4xx
  • http_5xx
HealthCheckType String No tcp

The type of health check.

Valid values:

  • tcp(default value)
  • http
VServerGroupId String No rsp-cige6j****

The ID of the vServer group.

MasterSlaveServerGroupId String No rsp-0bfucw****

The ID of the primary/secondary server group.

Note You cannot specify the vServer group ID and primary/secondary server group ID at the same time.
AclId String No 1323

The ID of the Access Control List (ACL) to which the listener is bound.

This parameter is required when the AclStatus parameter is set to on.

AclType String No black

The type of ACL.

  • white: specifies the ACL as a whitelist. Only requests from the IP addresses or CIDR blocks in the ACL are forwarded. Whitelists apply to scenarios where only specific IP addresses are allowed to access an application.

    Risks may occur if the whitelist is improperly set.

    After you set a whitelist for an SLB listener, only requests from IP addresses that are added to the whitelist are distributed by the listener.

    If the whitelist is enabled without IP addresses specified, the SLB listener does not forward requests.

  • black: specifies the ACL as a blacklist. All requests from the IP addresses or CIDR blocks in the ACL are rejected. Blacklists apply to scenarios that require you to block access from specific IP addresses to an application.

    If the blacklist is enabled but the corresponding ACL does not contain IP addresses, the SLB listener forwards all requests.

This parameter takes effect if the AclStatus parameter is set to on.

AclStatus String No off

Specifies whether to enable the access control feature.

Valid values:

  • on
  • off(default value)
Description String No CreateListeners.

The description of the listener.

The description must be 1 to 80 characters in length, and can contain letters, digits, hyphens (-), forward slashes (/), periods (.),and underscores (_). Chinese characters are supported.

ConnectionDrain String No off

Specifies whether to enable connection draining. Valid values:

  • on: enables connection draining.
  • off: disables connection draining.
ConnectionDrainTimeout Integer No 300

The timeout period for the connection draining feature. If ConnectionDrain is set to on, this parameter is required.

Value values: 10 to 900. Unit: seconds.

Response parameters

Parameter Type Example Description
RequestId String CEF72CEB-54B6-4AE8-B225-F876FF7BA984

The ID of the request.

Examples

Sample requests

http(s)://[Endpoint]/?Action=CreateLoadBalancerTCPListener
&Bandwidth=-1
&ListenerPort=80
&LoadBalancerId=lb-bp1b6c719dfa08ex****
&<Common request parameters>

Sample success responses

XML format

<CreateLoadBalancerTCPListenerResponse>
     <RequestId>CEF72CEB-54B6-4AE8-B225-F876FF7BA984</RequestId>
</CreateLoadBalancerTCPListenerResponse>

JSON format

{"RequestId":" CEF72CEB-54B6-4AE8-B225-F876FF7BA984"}

Error codes

HttpCode Error code Error message Description
400 Abs.VServerGroupIdAndMasterSlaveServerGroupId.MissMatch The parameters VServerGroupId or MasterSlaveServerGroupId miss match. The error message returned because the VServerGroupId parameter or the MasterSlaveServerGroupId parameter does not match.
400 LbNotSupportTcpssl You cannot create a TCP SSL type listener for the specified load balancer. The error message returned because the specified instance does not allow you to create tcpssl listeners.
400 LbSupportTcpsslOnly The specified load balancer supports TCP SSL type listener only. The error message returned because the specified instance allows you to create only tcpssl listeners.
400 ListenerNotSupportRule You cannot create a rule for the specified listener. The error message returned because the specified listener does not allow you to create forwarding rules.

For a list of error codes, visit the API Error Center.