Event Driven Architecture — Series Part I — Create a kafka lab in WSL2
[Last Updated : 07 of January of 2023]
Nowadays the use of event-driven architectures sounds a lot in all professional environment. This makes me wonder how to learn to solve their integration in the design of solutions and architecture proposal.
Designing solutions and architectures involves knowing what you have in your hands, and getting down to work by preparing a laboratory where you can start experimenting.
This basics config are create in a windows 10 machine with WSL2, due the use of Windows Linux Subsytem can be ideal for this type of labs, it does not mess up your windows environment and you work in this case on ubuntu 20.4 under command line, which gives simplicity and ease of use.
Prerequisites and necessary tools.
It is necessary to have the following items pre-installed and configured before installing Kafka
- WSL installed on and configured on your Windows.
- curl, for kakfa download.
- Java 8 or higher, as a specific prerequisite, to run kafka :
Tips: It is a minimum requirement to have Java jdk8 installed at least and to have it configured in the ~/ect/environment file. For example in the case of jdk 11, the path that must be reflected in kacfka must be JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
- Nano as a text editor to prepare the configuration files. Nano is installed by default on most Linux distributions
- Windows terminal, as an ideal tool to manage the different sessions of your distribution installed on WSL2 Windows terminal
Download Kafka
kafka has several distributions to work with it, we use in this case the latest version and the open source distribution for installation, due without containers, for ease of use and for its reduced consumption to be able to mount a basic environment of a fast way.
Note :In case you want to work with containers, a recommended commercial distribution, to set up your own laboratory, could be Confluent.
This, you can download it as a reference version on the apache kafka web page. to do this in a session of our ubuntu, we have opened in windows terminal, and using the command curl:
curl “https://ftp.cixug.es/apache/kafka/2.7.0/kafka_2.13-2.7.0.tgz" -o ~/downloads/kafka_2.13–2.7.0.tgzOnce downloaded we only have to position ourselves in our download directory and unzip the :
$ cd ~/downloads/
$ tar -xzf kafka_2.13–2.7.0.tgzIf you do not want to follow the additional configuration discussed here with a view to include the most common commands in files to be executed later you can go directly to the next article in the series where we start working with this lab, directly from the directory where kakfa is installed.
Even driven Architecture — Series Part II — Sending and consuming Messages from CLI with Kafka
Basic configuration of kafka to start working
We create two configuration files, which have the peculiarity of configuring the path relative to kafka, and the startup configuration that comes by default in the zookeeper.properties and server.properties files, being able to use them in the future to include more startup configurations and reduce the interaction of the command line.
To do this from terminal services we create a folder where we create our configurations and where we copy the two files that come in the initial distribution of Kafka. To do this we create the directory, we position ourselves in it, and we obtain the copy the commented files in the corresponding folder (in this case Kafka) complete path with pwd.
$ mkdir kafka
$ cd kafka
$ pwdCopy the commented files in the corresponding folder (in this case Kafka)
cp zooker.properties [path_pwd]
cp server.properties [path.pwd]Then we create two files startkafka and starkafkades. In the first file, using an editor (for example with nano), copy the following content
# path to specific kafka and java version
echo “start path”
export KAFKA_HOME=/home/jlmartinez/downloads/kafka_2.13–2.7.0
export PATH=”$PATH:${KAFKA_HOME}/bin”
# Start the ZooKeeper service
echo “start Kafka Services — Zookeeper”
zookeeper-server-start.sh zookeeper.propertiesand the other file :
echo “start path”
export KAFKA_HOME=/home/jlmartinez/downloads/kafka_2.13–2.7.0
export PATH=”$PATH:${KAFKA_HOME}/bin”
# Start the kafka service
echo “start Kafka Services — Server”
zookeeper-server-start.sh server.propertiesNow we only have to open two tabs from Windows terminal where we run with bash each of the two files having kafka already configured, with which we finish the start of kafka and we have a basic environment configured with which to work on this amazing technology.
Java udpate and setting Versión
The commands to install and verify java version, for a correct environment:
Install jdk into ubuntu environment :
sudo apt updatesudo apt install openjdk-11-jdk
Check version of java :
java — versionTo changed the default version :
sudo update-alternatives — config javaJava Home environment variables with the path selected in the previous command, mus be update in a new line and the end of the document, like this JAVA_HOME=”/usr/lib/jvm/java-11-openjdk-amd64"
sudo nano /etc/environmentCommand to propagate the changed without login/logout the session:
source /etc/environmentAnd to verify the changes, can execute this command
echo $JAVA_HOMESet WSL2 Memory usage
In some case, like latops with low Memory (8 GB or below), its necesary to setiing the WSL2 memory usage in order to havig a freendly enviroment
Access to directory /etc into your Linux distribution and create or update the file wsl.cfg, inserting the next lines, to limit the memory consumed of your computer (4GBytes looks fine for my in a laptop with 8 GBytes).
[WSL2]
memory = 4GBThis configuration is per distribution.
After of this, from a powershell console of the Windows Terminal, run the next command y order to shutdown and restart the wsl distribution.
wsl --shutdownNext Steps
Once this software is installed you can continue with the next chapter of the series in the following link of medium
