Skip to content

Commit adf3cda

Browse files
Wait for ZK to be listening when using provided ZK (#1039)
1 parent d4fe4b7 commit adf3cda

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/modules/kafka/src/kafka-container.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,17 @@ export class KafkaContainer extends GenericContainer {
300300
}
301301

302302
private commandZookeeper(): string {
303-
let command = "echo 'clientPort=" + DEFAULT_ZOOKEEPER_PORT + "' > zookeeper.properties\n";
303+
const port = DEFAULT_ZOOKEEPER_PORT;
304+
305+
let command = `echo 'clientPort=${DEFAULT_ZOOKEEPER_PORT}' > zookeeper.properties\n`;
304306
command += "echo 'dataDir=/var/lib/zookeeper/data' >> zookeeper.properties\n";
305307
command += "echo 'dataLogDir=/var/lib/zookeeper/log' >> zookeeper.properties\n";
306308
command += "zookeeper-server-start zookeeper.properties &\n";
309+
310+
command += `echo "Waiting for ZooKeeper to be ready on port ${port}..."\n`;
311+
command += `while ! (echo > /dev/tcp/localhost/${port}) &> /dev/null; do sleep 0.1; done\n`;
312+
command += `echo "ZooKeeper is ready."\n`;
313+
307314
return command;
308315
}
309316
}

0 commit comments

Comments
 (0)