A maven project for interacting with Kafka.
Your work on the homework is to use any resources you can find to answer all the questions asked in theory.md and KafkaHomework.scala. Here is what you need to complete:
- Start by completing your answers to the questions in src/main/com.labs1904.hwe/homework/theory.md. There are further instructions on theory.md that give tips and helpful resources to guide you in the right direction. You are welcome to use any resources you can find (youtube, articles, books, your teachers, etc)
- Complete the TODOs in KafkaHomework.scala in the same directory as theory.md
- Important Note - Do not commit the bootstrap servers to github. You are welcome to commit and push your work to github, but make sure to change them back to "change-me" before committing and pushing to github.
Fill out the following environment variables with values provided by the HWE admins:
- HWE_KAFKA_BOOTSTRAP_SERVER
- HWE_KAFKA_DEFAULT_TOPIC
- HWE_KAFKA_PASSWORD
- HWE_KAFKA_USERNAME
Then, navigate to com.labs1904.hwe.ConnectionTest and run the class to make sure you have an output that says Message Received:
A topic exists called "question-1" with tab delimited strings as its messages. Navigate to HweConsumer and write code to:
- Consume from the topic
- Print out the strings to understand their structure.
Modify your solution to the problem above by adding the following functionality:
- Create a case class named
RawUser
that matches the data's structure. - Split the TSV by tabs /t, and populate an instance of the scala case class that you created.
Modify your solution to the problem above by adding the following functionality:
- Create a new case class named
EnrichedUser
that adds 2 new columns:- numberAsWord - convert the first field (which is numeric) into a string using the
Util.mapNumberToWord
function - hweDeveloper - hard-code your name here. (This is so you can tell your data apart from everyone else's)
- numberAsWord - convert the first field (which is numeric) into a string using the
- For each record processed, populate an instance of
EnrichedUser
Modify your solution to the problem above by adding the following functionality:
- Convert your instance of
EnrichedUser
into a comma-separated string of values - Write the comma-separated string to a topic named
question-1-output
- Terminate your
HweConsumer
process and useSimpleConsumer
to try and find your data!
There is likely a problem with your IP address - fill out the What's Your IP form again and ask a TA to re-approve you.
When I run the ConnectionTest, it complains "Failed to construct the kafka consumer!: Failed to load SSL keystore"
If you see an error message like this:
Exception in thread "main" org.apache.kafka.common.KafkaException: Failed to construct kafka consumer ... Caused by: org.apache.kafka.common.KafkaException: org.apache.kafka.common.KafkaException: Failed to load SSL keystore src\main\resources\kafka.client.truststore.jks of type JKS
then there are 2 things to double check here:
-
Make sure exactly one of the 2 lines below is uncommented, depending if you are on a Windows or a Mac:
//Use this for Windows val trustStore: String = "src\\main\\resources\\kafka.client.truststore.jks" //Use this for Mac //val trustStore: String = "src/main/resources/kafka.client.truststore.jks"
-
In your Intellij Run Configuration, make sure your "Working Directory" is set to "C:\Path\To\Your\Downloaded\Repo\kafka-hello-world"
When I run the ConnectionTest, I get an error about "SaslAuthenticationException: Authentication failed during authentication due to invalid credentials with SASL mechanism SCRAM-SHA-512
"!
If you see an error message like this below, your username or password is incorrect.
Exception in thread "main" org.apache.kafka.common.errors.SaslAuthenticationException: Authentication failed during authentication due to invalid credentials with SASL mechanism SCRAM-SHA-512
What is the CAP theorem, and where does Kafka fit within it?