What's New in API7 Enterprise 3.2.12: Supporting Stream Routes
Published: 2024-05-24 09:33:09

In [API7 Enterprise](https://api7.ai/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.

![Add Stream Service Type](https://static.apiseven.com/uploads/2024/05/24/47eJT7A6_stream-route-1.png)

### 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.

![Add Stream Routes for Services](https://static.apiseven.com/uploads/2024/05/24/EYL9n70I_stream-route-2.png)

Fill in the route name, description, and relevant route configuration in the form. Here, we configure a route for proxying MySQL service.

![Details of Adding Stream Routes](https://static.apiseven.com/uploads/2024/05/24/D0dpeVzc_stream-route-3.png)

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.

![MySQL Routes Added](https://static.apiseven.com/uploads/2024/05/24/41nDGBio_stream-route-4.png)

### 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.

![Add Node for MySQL Service](https://static.apiseven.com/uploads/2024/05/24/0pN52UW6_stream-route-5.png)

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](https://api7.ai/blog/api7-3.2.9-upgraded-health-check-configuration) 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:

1. [`ip-restriction`](https://docs.api7.ai/hub/ip-restriction/): Provides IP access control capabilities.

2. [`limit-conn`](https://apisix.apache.org/docs/apisix/3.3/plugins/limit-conn/): This plugin can restrict the number of concurrent requests from clients to a single service.

3. [`prometheus`](https://docs.api7.ai/hub/prometheus): Provides system monitoring and alerting capabilities for stream routes.

4. [`syslog`](https://docs.api7.ai/hub/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.