In API7 Enterprise 3.2.12, support for stream routes has been introduced, enabling TCP/UDP protocol traffic proxy and load balancing.
By configuring stream routes, API7 Enterprise can proxy requests for services such as MySQL and MongoDB based on the TCP protocol. It can also proxy applications like Redis that can be configured with either TCP or UDP protocols. This enables effective management and optimization of TCP/UDP network traffic.
How to Use Stream Routes in API7 Enterprise?
Adding Stream Service
When manually adding a service, an option for service type selection has been added, supporting two types: HTTP and Stream, representing Layer 7 proxy and Layer 4 proxy, respectively. If the service type is selected as Stream
, the upstream schema can be chosen as either TCP
or UDP
. It is important to note that once the service type is selected, it can not be changed, so ensure the correct service type is chosen.
Adding Stream Routes
After successfully creating a Stream-type service, it will be directed to the service details page. The next step is to add routes by clicking the Add Stream Route
button.
Fill in the route name, description, and relevant route configuration in the form. Here, we configure a route for proxying MySQL service.
Compared to regular HTTP route configurations, stream routes has three different configuration options.
Server Address: This is the address where the gateway server receives stream route connections, serving as the entrance for stream route traffic into the gateway. When clients seek to establish connections, they send requests to this address, and the gateway forwards or handles these requests based on the predefined routing rules.
Server Port: It is used to specify the port on which the gateway server listens for traffic.
Remote Address: It is the client address that initiates the request. Only requests sent from client addresses that are the same as the remote address can be forwarded, thus enabling traffic management for specific clients.
After successfully creating the route, we can see the newly added MySQL route in the list.
Configuring Upstream Nodes and Publishing the Service
Next, we will publish the service to the gateway group and add an upstream node corresponding to the MySQL service.
After the service is published, when the gateway server at 127.0.0.10
and port 9101
receives a request, this route will be responsible for handling the request and forwarding it to the upstream MySQL service.
In addition to the basic request forwarding feature, after service publication, the performance and security of the service can be enhanced through a series of configurations. For example, load balancing strategies can be configured for stream routes to ensure traffic is evenly distributed among multiple upstream MySQL servers, thereby improving system scalability and fault tolerance.
Furthermore, health check mechanisms can be set up to periodically monitor the status of upstream servers, ensuring only healthy servers receive and forward requests, and avoiding service interruptions due to server failures.
Supported Plugins
Currently, there are four plugins supported for stream routes:
ip-restriction
: Provides IP access control capabilities.limit-conn
: This plugin can restrict the number of concurrent requests from clients to a single service.prometheus
: Provides system monitoring and alerting capabilities for stream routes.syslog
: Records and sends system logs.
These four plugins collectively enhance the security, stability, monitoring, and maintainability of stream routes.
Conclusion
The stream routes feature in API7 Enterprise 3.2.12 provides users with more robust and flexible TCP/UDP protocol traffic management, contributing to improved application reliability and scalability. It brings enhanced network traffic management, higher system reliability and operational efficiency, and superior business adaptability for enterprise users, making it valuable for supporting the operation of critical enterprise applications.