ene-rs / ene-kafka

An easy-to-use Kafka client for Rust
Apache License 2.0
13 stars 0 forks source link

Unclear consumer declaration interface and implementation. #10

Closed Abdullahsab3 closed 2 months ago

Abdullahsab3 commented 2 months ago

The current implementation of the kafka_consumer macro can be a bit unclear to use or debug. Now, it works as follows:

let consumer = kafka_consumer!(
    topic = KafkaTopic {
        name: "test".to_string(),
        content_type: ContentType::Json
    },
    dlq_topic = KafkaTopic {
        name: "test-dlq".to_string(),
        content_type: ContentType::Json
    },
    consumer_group_id = "test-group",
    bootstrap_servers = bootstrap_servers,
    handlers = [
        EntityCreatedEventHandler -> EntityCreatedEventHandler {}
    ]
);

However it would be much simpler to maintain if the handlers definitions match a little bit how Rust declares new variables. That is:

let consumer = kafka_consumer!(
    topic = KafkaTopic {
        name: "test".to_string(),
        content_type: ContentType::Json
    },
    dlq_topic = KafkaTopic {
        name: "test-dlq".to_string(),
        content_type: ContentType::Json
    },
    consumer_group_id = "test-group",
    bootstrap_servers = bootstrap_servers,
    handlers = {
        entity_created_event_handler: EntityCreatedEventHandler = EntityCreatedEventHandler {}
    }
);

This would elminate the need for generate_handler_types_enum and for the handlers vector, and it would make it possible to have the entire handlers implementation done statically at compile time, without the need for the heap (vector)