Hawk-Rust Series: Kafka with Rust

Hawk

In this post, we will see why we used Kafka for Hawk and how we implemented Kafka for Hawk since Hawk is built on Rust it will be interesting to learn how one can use Kafka with Rust.
If you don’t have any idea what Hawk is here is a brief overview.
Hawk is an image recognition application built in Rust using AWS services.
For more details, you can refer here.

1. What is Kafka?

Apache Kafka is a highly scalable, fast and fault-tolerant messaging application used for streaming applications and data processing. This application is written in Java and Scala programming languages. Basically, Kafka is a message queuing system.
A message queuing system helps in transferring the data between applications so that the applications can just concentrate on the data rather than being focused on how the data is being transferred and shared.

2. Why we used Kafka?

You already know Hawk is a two-way authentication application. First is through RFID scanning and second is the Image recognition of the user.
And these are two different application on its own. So, when the user scans its RFID it will be acting as a producer and put that employee’s id number into the topic which was already subscribed by our second application. The Moment our image recognition application gets the employee id it will trigger the camera and authenticates the user. This way Kafka help us connecting our two application.

3. How we integrate Kafka with Hawk

a.) Installation of Kafka

This crate is working with cargo. You just need to put Kafka as a dependency on cargo.toml file of your project.

[dependencies]
kafka = "0.7"

b.) Consumer API

This is a higher-level consumer API for Kafka and is provided by the module kafka::consumer. It allows an application to subscribe to one or more topics and process the stream of records produced to them.

c.) Producer API

This is a higher-level producer API for Kafka and is provided by the module kafka::producer. It allows an application to publish a stream of records to one or more Kafka topics.

Architecture design

Conclusion

Congratulations folks! In this post, we explored how Kafka helps us to bind our two applications of Hawk.
For more reference and contributing to our open source project Hawk, you can visit here.
Thank you for reading. I hope this blog post was helpful to you. Let me know your views, questions, comments in the comment section below.


Knoldus-blog-footer-image

Written by 

Alok Jha is the Trainee Software Consultant at Knoldus Software LLP. He has good knowledge of languages C, C++, Java and currently exploring Rust. As a fresher, he always tries to explore the different type of software and tools.

Knoldus Pune Careers - Hiring Freshers

Get a head start on your career at Knoldus. Join us!