Skip to main content

Version: 3.2.12.0

Proxy Transport Layer (L4) Traffic

API7 Enterprise can handle transport layer (L4) TCP and UDP traffic dedicated or in addition to handling application layer (L7) traffic.

This tutorial walks through configuring a stream route to proxy L4 traffic between clients and a MySQL server.

Prerequisites

  1. Install API7 Enterprise.
  2. Obtain a user account with Super Admin or API Provider role.
  3. Rename the default gateway group to Test Group and configure the network. Test Group will be the API gateway for your test environment.
  4. Have at least one gateway instance in the Test Group.
  5. Install a MySQL client to validate the stream route.

Start a MySQL Server

Start a MySQL server inside Docker and use the default API7 Enterprise network as shown below:

docker run -d \
--name mysql \
--network=api7-ee_api7 \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=password \
mysql:8.4 \
mysqld --mysql-native-password=ON

Add a Service with Stream Routes

  1. Select Service Hub from the side navigation bar, then click Add Service.
  2. Select Add Manually.
  3. From the Add Service dialog box, do the following:
    1. In the Name field, enter MySQL.
    2. In the Service Type field, choose Stream(Layer 4 Proxy).
    3. By default, the Upstream Scheme is TCP.
  4. Click Add.
  5. Inside the service, click Add Stream Route.
  6. From the Add Stream Route dialog box, do the following:
    1. In the Name field, enter stream-route-mysql.
    2. In the Server Address field, enter 127.0.0.1.
    3. In the Server Port filed, enter 2000.
  7. Click Add.
info

Make sure to expose the server port, 2000, to the host machine.

Publish the Service Using Upstream Nodes

  1. Select Service Hub from the side navigation bar and then select MySQL service.
  2. Click Publish Now.
  3. Select Test Group and then click Next.
  4. From the dialog box, do the following:
    1. In the New Version field, enter 1.0.0.
    2. By default, the How to find the upstream field is Use Nodes.
    3. Click Add Node. From the dialog box, do the following:
      1. In the Host and Port fields, enter your MySQL IP address and 3306 respectively.
      2. In the Weight field, use the default value 100.
    4. Click Add.
  5. Confirm the service information and then click Publish.

Validate the Stream Route

Establish a connection with the MySQL server through API7 Enterprise using the MySQL client. Connect as root using the password configured before:

mysql --host=127.0.0.1 --port=2000 -u root -p

You should see the MySQL prompt as shown below:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.4.0 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

API7.ai Logo

API Management for Modern Architectures with Edge, API Gateway, Kubernetes, and Service Mesh.

Product

API7 Cloud

SOC2 Type IIISO 27001HIPAAGDPRRed Herring

Copyright © APISEVEN PTE. LTD 2019 – 2025. Apache, Apache APISIX, APISIX, and associated open source project names are trademarks of the

Apache Software Foundation