Click here to Skip to main content
15,887,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to launch AKHQ using Testcontainers, however when launching UI, I get the following message:

C#
/ http://localhost:62732/
{
  "message": "Couldn't find any clusters on your configuration file, 
   please ensure that the configuration file is loaded correctly",
  "_links": {
    "self": {
      "href": "/",
      "templated": false
    }
  }
}


What I have tried:

C#
			var containerName = Guid.NewGuid().ToString();

			#region Zookeeper
			var zookeeperContainerName = $"zookeeper_{containerName}";
			var zookeeperContainer = new ContainerBuilder()
				// Set the image for the container
				.WithImage("confluentinc/cp-zookeeper:latest")
				.WithName(zookeeperContainerName)
				// Bind port 2181 of the container to a 
                // random port on the host.
				.WithPortBinding(2181, true)
				.WithEnvironment(new Dictionary<string, string>
				{
					{"ZOOKEEPER_CLIENT_PORT", "2181"},
					{"ZOOKEEPER_TICK_TIME", "2000"}
				})
				.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(2181))
				.Build();

			await zookeeperContainer.StartAsync()
				.ConfigureAwait(false);
#endregion

			#region Kafka
			var zookeeperHostPort = 
                zookeeperContainer.GetMappedPublicPort(2181);
			var kafkaContainerName = $"kafka_{containerName}";
			var kafkaHostPort = FindFreePort();
			var kafkaContainer = new ContainerBuilder()
				// Set the image for the container
				.WithImage("confluentinc/cp-kafka:latest")
				.WithName(kafkaContainerName)
				.WithHostname(kafkaContainerName)
				.WithPortBinding(kafkaHostPort, 9092)
				.WithEnvironment(new Dictionary<string, string>
				{
					{"KAFKA_BROKER_ID", "1"},
					{"KAFKA_ZOOKEEPER_CONNECT", 
                      $"host.docker.internal:{zookeeperHostPort}"},

					{"KAFKA_LISTENER_SECURITY_PROTOCOL_MAP", 
                     "PLAINTEXT:PLAINTEXT,PLAINTEXT_INTERNAL:PLAINTEXT"},
					{"KAFKA_LISTENERS", 
                     "PLAINTEXT://:9092,PLAINTEXT_INTERNAL://:29092"},
					{"KAFKA_ADVERTISED_LISTENERS", 
                    $"PLAINTEXT://localhost:{kafkaHostPort},
                     PLAINTEXT_INTERNAL://{kafkaContainerName}:29092"},
					{"KAFKA_INTER_BROKER_LISTENER_NAME", 
                     "PLAINTEXT_INTERNAL"},
					{"KAFKA_TRANSACTION_STATE_LOG_MIN_ISR", "1"},
					{"KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR", "1"},
					{"KAFKA_AUTO_CREATE_TOPICS_ENABLE", "true"},
					{"KAFKA_DELETE_TOPIC_ENABLE", "true"},
					{"KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR", "1"},
				})
				.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(9092))
				.Build();

			await kafkaContainer.StartAsync()
				.ConfigureAwait(false);
			#endregion

			#region akhq
			var akhqContainerName = $"akhq_{containerName}";
			var akhqHostPort = 62732;//FindFreePort();
			var akhqContainer = new ContainerBuilder()
				// Set the image for the container
				.WithImage("tchiotludo/akhq:latest")
				.WithName(akhqContainerName)
				.WithPortBinding(akhqHostPort, 8082)
				.WithEnvironment(new Dictionary<string, string>
				{
					{"MICRONAUT_SERVER_PORT", "8082"},
					{"AKHQ_CONFIGURATION", 
                    $"\r\n{akhqContainerName}:\r\nconnections:\r\ndocker-kafka-server:\r\nproperties:\r\nbootstrap.servers: \" 
                   {kafkaContainerName}:29092\"\r\n"}
				})
				.WithWaitStrategy(Wait.ForUnixContainer().UntilPortIsAvailable(8082))
				.Build();

			await akhqContainer.StartAsync()
				.ConfigureAwait(false);
#endregion
Posted
Updated 12-Sep-23 11:37am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900