Kafka Producer and Consumer in Rust
This repository contains Rust-based implementations of a Kafka producer and a Kafka consumer. It leverages the rdkafka library to communicate with Kafka and manage the production and consumption of messages.
Prerequisites
- Rust: Ensure you have Rust and Cargo installed on your machine.
- Kafka: A running Kafka cluster that you can connect to.
Setup
-
Clone the Repository:
-
Navigate to the Repository:
-
Build the Code:
Producer
The Kafka producer is a higher-level interface for producing messages to Kafka. It encapsulates the process of initializing a connection to the Kafka broker and sending messages to a specified topic.
Usage
To initialize the producer:
let producer = new;
To send a message to a Kafka topic:
let msg = new;
producer.send_message.await;
Custom Configurations
You can provide custom configurations while initializing the producer:
let mut configs = new;
configs.insert;
let producer_with_configs = new;
Consumer
The Kafka consumer provides functionality to consume messages from a Kafka topic.
Usage
To initialize the consumer:
let consumer = new;
To consume messages:
if let Some = consumer.poll.await
Custom Configurations
Just like the producer, the consumer also supports custom configurations:
let mut new_configs = new;
new_configs.insert;
consumer.set_client_config;
Running Tests
To run tests:
Ensure your Kafka broker is running and the test topic exists.
Contribution
We welcome contributions! Feel free to open issues, submit pull requests, or just spread the word.
License
This project is licensed under the MIT License.