import org.springframework.context.annotation.Import;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.test.context.EmbeddedKafka;
+import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.KafkaContainer;
import org.testcontainers.containers.Network;
Network network = Network.newNetwork();
+ @Container
+ GenericContainer HAPROXY =
+ new GenericContainer(DockerImageName.parse("haproxytech/haproxy-debian:2.8"))
+ .withNetwork(network)
+ .withNetworkAliases("haproxy")
+ .withClasspathResourceMapping(
+ "haproxy.cfg",
+ "/usr/local/etc/haproxy/haproxy.cfg",
+ BindMode.READ_ONLY)
+ .withClasspathResourceMapping(
+ "sharding.map",
+ "/usr/local/etc/haproxy/sharding.map",
+ BindMode.READ_WRITE)
+ .withExposedPorts(8400, 8401, 8404, 5555)
+ .withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("HAPROXY"));
+
@Container
KafkaContainer KAFKA =
new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:7.4.0"))
.withCommand(
"--chat.backend.instance-id=backend-1",
"--chat.backend.services=kafka",
- "--chat.backend.kafka.bootstrap-servers=kafka:9999"
+ "--chat.backend.kafka.bootstrap-servers=kafka:9999",
+ "--chat.backend.kafka.instance-uri=http://backend-1:8080",
+ "--chat.backend.kafka.num-partitions=10",
+ "--chat.backend.kafka.client-id-prefix=B1",
+ "--chat.backend.kafka.haproxy-runtime-api=haproxy:8401",
+ "--chat.backend.kafka.haproxy-map=/usr/local/etc/haproxy/sharding.map"
)
.withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("BACKEND-1"));
.withCommand(
"--chat.backend.instance-id=backend-2",
"--chat.backend.services=kafka",
- "--chat.backend.kafka.bootstrap-servers=kafka:9999"
+ "--chat.backend.kafka.bootstrap-servers=kafka:9999",
+ "--chat.backend.kafka.instance-uri=http://backend-2:8080",
+ "--chat.backend.kafka.num-partitions=10",
+ "--chat.backend.kafka.client-id-prefix=B2",
+ "--chat.backend.kafka.haproxy-runtime-api=haproxy:8401",
+ "--chat.backend.kafka.haproxy-map=/usr/local/etc/haproxy/sharding.map"
)
.withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("BACKEND-2"));
.withCommand(
"--chat.backend.instance-id=backend-3",
"--chat.backend.services=kafka",
- "--chat.backend.kafka.bootstrap-servers=kafka:9999"
+ "--chat.backend.kafka.bootstrap-servers=kafka:9999",
+ "--chat.backend.kafka.instance-uri=http://backend-3:8080",
+ "--chat.backend.kafka.num-partitions=10",
+ "--chat.backend.kafka.client-id-prefix=B3",
+ "--chat.backend.kafka.haproxy-runtime-api=haproxy:8401",
+ "--chat.backend.kafka.haproxy-map=/usr/local/etc/haproxy/sharding.map"
)
.withLogConsumer(new Slf4jLogConsumer(log, true).withPrefix("BACKEND-3"));
@Test
void test() throws InterruptedException
{
- Thread.sleep(15000);
+ Thread.sleep(150000);
}
}
--- /dev/null
+# Config from Blog-article "How to Run HAProxy with Docker"
+defaults
+ mode http
+ timeout client 10s
+ timeout connect 5s
+ timeout server 10m
+ timeout http-request 10s
+ log global
+
+global
+ stats socket ipv4@:8401 level admin
+ stats socket /var/run/haproxy.sock mode 666 level admin
+ stats timeout 2m
+
+frontend stats
+ bind *:8404
+ stats enable
+ stats uri /
+ stats refresh 10s
+
+frontend frontend
+ bind :8400
+ default_backend random
+ use_backend %[req.hdr(X-Shard),map(/usr/local/etc/haproxy/sharding.map)]
+
+backend random
+ server b1 backend-1:8080 check
+ server b2 backend-2:8080 check
+ server b3 backend-3:8080 check
+
+backend backend_1
+ server b1 backend-1:8080 check
+
+backend backend_2
+ server b2 backend-2:8080 check
+
+backend backend_3
+ server b3 backend-3:8080 check
+
+userlist haproxy-dataplaneapi
+ user juplo insecure-password juplo
+
+program api
+ command /usr/bin/dataplaneapi --host 0.0.0.0 --port 5555 --haproxy-bin /usr/sbin/haproxy --config-file /usr/local/etc/haproxy/haproxy.cfg --reload-cmd "kill -SIGUSR2 1" --restart-cmd "kill -SIGUSR2 1" --reload-delay 5 --userlist haproxy-dataplaneapi
+ no option start-on-reload
+