|
3 | 3 |
|
4 | 4 | import io.github.kimmking.gateway.inbound.HttpInboundServer; |
5 | 5 |
|
| 6 | +import java.util.Arrays; |
| 7 | + |
6 | 8 | public class NettyServerApplication { |
7 | 9 |
|
8 | 10 | public final static String GATEWAY_NAME = "NIOGateway"; |
9 | | - public final static String GATEWAY_VERSION = "1.0.0"; |
| 11 | + public final static String GATEWAY_VERSION = "3.0.0"; |
10 | 12 |
|
11 | 13 | public static void main(String[] args) { |
12 | | - String proxyServer = System.getProperty("proxyServer","http://localhost:8088"); |
| 14 | + |
13 | 15 | String proxyPort = System.getProperty("proxyPort","8888"); |
14 | | - |
15 | | - // http://localhost:8888/api/hello ==> gateway API |
16 | | - // http://localhost:8088/api/hello ==> backend service |
17 | | - |
| 16 | + |
| 17 | + // 这是之前的单个后端url的例子 |
| 18 | +// String proxyServer = System.getProperty("proxyServer","http://localhost:8088"); |
| 19 | +// // http://localhost:8888/api/hello ==> gateway API |
| 20 | +// // http://localhost:8088/api/hello ==> backend service |
| 21 | + // java -Xmx512m gateway-server-0.0.1-SNAPSHOT.jar #作为后端服务 |
| 22 | + |
| 23 | + |
| 24 | + // 这是多个后端url走随机路由的例子 |
| 25 | + String proxyServers = System.getProperty("proxyServers","http://localhost:8801,http://localhost:8802"); |
18 | 26 | int port = Integer.parseInt(proxyPort); |
19 | 27 | System.out.println(GATEWAY_NAME + " " + GATEWAY_VERSION +" starting..."); |
20 | | - HttpInboundServer server = new HttpInboundServer(port, proxyServer); |
21 | | - System.out.println(GATEWAY_NAME + " " + GATEWAY_VERSION +" started at http://localhost:" + port + " for server:" + proxyServer); |
| 28 | + HttpInboundServer server = new HttpInboundServer(port, Arrays.asList(proxyServers.split(","))); |
| 29 | + System.out.println(GATEWAY_NAME + " " + GATEWAY_VERSION +" started at http://localhost:" + port + " for server:" + server.toString()); |
22 | 30 | try { |
23 | 31 | server.run(); |
24 | 32 | }catch (Exception ex){ |
|
0 commit comments