ds_event_stream_rs_sdk/lib.rs
1//! # DS Event Stream Rust SDK
2//!
3//! A comprehensive Rust SDK for working with the DS Event Stream, providing
4//! high-level abstractions for producing and consuming events from Kafka.
5//!
6//! ## Features
7//!
8//! - **Event Models**: Type-safe event structures with serialization support
9//! - **Kafka Producer**: Async producer for sending events to Kafka topics
10//! - **Kafka Consumer**: Stream-based consumer for processing events
11//! - **Topic Management**: Predefined topic constants and utilities
12//! - **Admin Utilities**: Helper functions for Kafka cluster management
13//!
14//! ## Quick Start
15//!
16//! Add to your `Cargo.toml`:
17//! ```toml
18//! [dependencies]
19//! ds-event-stream-rs-sdk = "0.1.0"
20//! ```
21//!
22//! ### Basic Usage
23//!
24//! ```no_run
25//! use ds_event_stream_rs_sdk::{
26//! model::{EventStream, topics::Topic},
27//! producer::KafkaProducer,
28//! consumer::KafkaConsumer,
29//! };
30//! use ds_event_stream_rs_sdk::error::{Result, SDKError};
31//! use ds_event_stream_rs_sdk::utils::{get_bootstrap_servers, Environment, ClientCredentials};
32//!
33//! use uuid::Uuid;
34//! use chrono::Utc;
35//! use tokio_stream::StreamExt;
36//! use rdkafka::message::Message;
37//!
38//! #[tokio::main]
39//! async fn main() -> Result<(), SDKError> {
40//! // Create an event
41//! let event = EventStream::new(
42//! Uuid::new_v4(),
43//! Uuid::new_v4(),
44//! "my-service".to_string(),
45//! "user.created".to_string(),
46//! "system".to_string(),
47//! None, None, None, None, None, None, None, None, None, None, None, None, None
48//! );
49//!
50//! let bootstrap_servers = get_bootstrap_servers(Environment::Development, false);
51//! let credentials = ClientCredentials { username: "username".to_string(), password: "password".to_string() };
52//!
53//! let producer = KafkaProducer::default(&bootstrap_servers, &credentials)?;
54//! producer.send_event(&Topic::IdpIdentityUserCreated, "user-123", &event, None).await?;
55//!
56//! let consumer = KafkaConsumer::default(&bootstrap_servers, &[Topic::IdpIdentityUserCreated], "group-id", &credentials)?;
57//! let mut stream = consumer.stream();
58//!
59//! while let Some(result) = stream.next().await {
60//! match result {
61//! Ok(msg) => println!("Received: {:?}", msg.topic()),
62//! Err(e) => eprintln!("Error: {}", e),
63//! }
64//! }
65//!
66//! Ok(())
67//! }
68//! ```
69//!
70//! ## Environment Variables
71//!
72//! The SDK uses the following environment variables:
73//!
74//! ## Error Handling
75//!
76//! The SDK provides comprehensive error types:
77//!
78//! - [`error::SDKError`]: Errors related to the SDK
79//! - [`producer::error::ProducerError`]: Errors related to message production
80//! - [`consumer::error::ConsumerError`]: Errors related to message consumption
81//! - [`utils::error::UtilsError`]: Errors related to administrative utilities
82//!
83//! ## Modules
84//!
85//! - [`model`]: Event data structures and topic definitions
86//! - [`producer`]: Kafka producer for sending events
87//! - [`consumer`]: Kafka consumer for receiving events
88//! - [`utils`]: Administrative utilities for Kafka management
89//! - [`error`]: Error types for the SDK
90
91pub mod consumer;
92pub mod error;
93pub mod model;
94pub mod producer;
95pub mod utils;