|
34 | 34 | #include <seastar/core/print.hh> |
35 | 35 | #include <seastar/net/inet_address.hh> |
36 | 36 | #include <seastar/util/defer.hh> |
| 37 | +#include <seastar/net/api.hh> |
37 | 38 | #include "../lib/stop_signal.hh" |
38 | 39 |
|
39 | 40 | namespace bpo = boost::program_options; |
@@ -80,6 +81,9 @@ int main(int ac, char** av) { |
80 | 81 | app_template app; |
81 | 82 |
|
82 | 83 | app.add_options()("port", bpo::value<uint16_t>()->default_value(10000), "HTTP Server port"); |
| 84 | + app.add_options()("load-balancing-algorithm", |
| 85 | + bpo::value<std::string>()->default_value("connection_distribution"), |
| 86 | + "Load balancing algorithm: connection_distribution, port, proxy_protocol_v2_and_port, fixed"); |
83 | 87 | app.add_options()("prometheus_port", bpo::value<uint16_t>()->default_value(9180), "Prometheus port. Set to zero in order to disable."); |
84 | 88 | app.add_options()("prometheus_address", bpo::value<sstring>()->default_value("0.0.0.0"), "Prometheus address"); |
85 | 89 | app.add_options()("prometheus_prefix", bpo::value<sstring>()->default_value("seastar_httpd"), "Prometheus metrics prefix"); |
@@ -132,7 +136,24 @@ int main(int ac, char** av) { |
132 | 136 | server->set_routes(set_routes).get(); |
133 | 137 | server->set_routes([rb](routes& r){rb->set_api_doc(r);}).get(); |
134 | 138 | server->set_routes([rb](routes& r) {rb->register_function(r, "demo", "hello world application");}).get(); |
135 | | - server->listen(port).get(); |
| 139 | + |
| 140 | + auto lba_str = config["load-balancing-algorithm"].as<std::string>(); |
| 141 | + server_socket::load_balancing_algorithm lba; |
| 142 | + if (lba_str == "connection_distribution") { |
| 143 | + lba = server_socket::load_balancing_algorithm::connection_distribution; |
| 144 | + } else if (lba_str == "port") { |
| 145 | + lba = server_socket::load_balancing_algorithm::port; |
| 146 | + } else if (lba_str == "proxy_protocol_v2_and_port") { |
| 147 | + lba = server_socket::load_balancing_algorithm::proxy_protocol_v2_and_port; |
| 148 | + } else if (lba_str == "fixed") { |
| 149 | + lba = server_socket::load_balancing_algorithm::fixed; |
| 150 | + } else { |
| 151 | + throw std::runtime_error("Invalid load balancing algorithm: " + lba_str); |
| 152 | + } |
| 153 | + |
| 154 | + listen_options lo; |
| 155 | + lo.lba = lba; |
| 156 | + server->listen(socket_address{net::inet_address{}, port}, lo).get(); |
136 | 157 |
|
137 | 158 | std::cout << "Seastar HTTP server listening on port " << port << " ...\n"; |
138 | 159 |
|
|
0 commit comments