// Metadata created by nebel
//
// ParentAssemblies: assemblies/tutorial/as_starting-services.adoc
// UserStory:

[id="starting-kafka"]
= Starting Kafka

ifdef::product[]
[NOTE]
====
{prodname} {debezium-version} requires Kafka Connect {debezium-kafka-version}.
Therefore, this procedure uses {debezium-kafka-version} of the Kafka broker.
For more information about compatibility between different versions of Kafka Connect and Kafka broker,
see the {link-kafka-docs}.html[Kafka documentation].
====
endif::product[]
ifdef::community[]
[NOTE]
====
{prodname} {debezium-version} has been tested against multiple versions of Kafka Connect.
Please refer to the https://debezium.io/releases[Debezium Test Matrix] to determine compatibility between {prodname} and Kafka Connect.
====
endif::community[]

.Procedure

. Open a new terminal and use it to start Kafka in a container.
+
--
This command runs a new container using version {debezium-docker-label} of the `quay.io/debezium/kafka` image:

[source,shell,options="nowrap",subs="+attributes"]
----
$ docker run -it --rm -p 9092:9092 \
  --name kafka --hostname kafka \
  -e CLUSTER_ID=<YOUR_UNIQUE_CLUSTER_IDENTIFIER> \
  -e NODE_ID=1 \
  -e NODE_ROLE=combined \
  -e KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka:9093 \
  -e KAFKA_LISTENERS=PLAINTEXT://kafka:9092,CONTROLLER://kafka:9093 \
  -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092 \
  quay.io/debezium/kafka:{debezium-docker-label}
----

`-it`:: The container is interactive,
which means the terminal's standard input and output are attached to the container.
`--rm`:: The container will be removed when it is stopped.
`--name kafka`:: The name of the container.
`--hostname kafka`:: Label ensures that the correct Kafka listener is paired to the container.
`-p 9092:9092`:: Maps port `9092` in the container to the same port on the Docker host so that applications outside of the container can communicate with Kafka.
`-e CLUSTER_ID=<YOUR_UNIQUE_CLUSTER_IDENTIFIER>`:: Unique identifier in the cluster. 
All the nodes within the cluster must have the same cluster ID.
`-e NODE_ID=1`:: Node identifier used in Raft protocol. 
Must be unique within the cluster.
`-e NODE_ROLE=combined`:: Node role within the cluster. 
Can be a controller, broker, or combined.
`-e KAFKA_CONTROLLER_QUORUM_VOTERS=1@kafka:9093`:: Specifies the nodes that act as voters in the Kafka controller quorum.
If multiple values are required, use a comma-separated list in the format `nodeId@host:port`, for example: `1@kafka1:9093,2@kafka2:9093,3@kafka3:9093`.
`-e KAFKA_LISTENERS=PLAINTEXT://kafka:9092,CONTROLLER://kafka:9093`:: Defines the internal endpoints and protocol for Kafka listeners.
`-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka:9092`:: Specifies how the broker advertises itself to external clients.

ifdef::community[]
[NOTE]
====
If you use Podman, run the following command:
[source,shell,options="nowrap",subs="+attributes"]
----
$ podman run -it --rm --name kafka --pod dbz -e HOST_NAME=127.0.0.1 quay.io/debezium/kafka:{debezium-docker-label}
----
====
endif::community[]

[NOTE]
====
In this tutorial, you will always connect to Kafka from within a Docker container.
Any of these containers can communicate with the `kafka` container by linking to it.
If you needed to connect to Kafka from _outside_ of a Docker container,
you would have to set the `-e` option to advertise the Kafka address through the Docker host
(`-e ADVERTISED_HOST_NAME=` followed by either the IP address or resolvable host name of the Docker host).
====
--

. Verify that Kafka started.
+
--
You should see output similar to the following:

[source,shell,options="nowrap"]
----
...
2025-07-22T11:43:00,935 - INFO  [main:AppInfoParser$AppInfo@125] - Kafka version: 4.0.0
2025-07-22T11:43:00,938 - INFO  [main:AppInfoParser$AppInfo@126] - Kafka commitId: 985bc99521dd22bb
2025-07-22T11:43:00,939 - INFO  [main:AppInfoParser$AppInfo@127] - Kafka startTimeMs: 1753184580923
2025-07-22T11:43:00,959 - INFO  [main:Logging@66] - [KafkaRaftServer nodeId=1] Kafka Server started   // <1>
----
<1> The Kafka node has successfully started and is ready for client connections. The terminal will continue to show additional output as Kafka generates it.
--
