Section III - module

processor.rs

To create the module, create a new file named processor.rs in the /src directory.

We inherit most of our use declarations from lib.rs using the use super::*; statement, but there is the kafka consumer use to add.

use super::*;
use kafka::consumer::{Consumer, FetchOffset, GroupOffsetStorage, Message};

Tests

Add the following unit test to the bottom of the module.

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_new_consumer() {
        let _consumer = OrderStatusProcessor::new(KAFKA_BROKERS.to_string(), "test".to_string(), "my-group".to_string());
    }
}

Code

Because the processor executable is a stand-alone microservice, we will follow an Object Oriented Design. This means we first define the OrderStatusProcessor object.

We then give the object functionality by using the impl OrderStatusProcessor {...} syntax. The constructor for the OrderStatusProcessor object is the new() function that returns a OrderStatusProcessor object.

Now is a good time to rerun the cargo test command to ensure all your tests still pass.

Last updated

Was this helpful?