Section IV - executable

Cargo.toml

daas-status-processing.rs

We are now ready to write the executable. To do this, we will working with the following files:

  • Cargo.toml (manifest)

  • src/bin/daas-status-processing.rs (executable)

Tests

Code

Declaring the Executable

In the Cargo.toml file, after the that last [[bin]] statement for sourcing, add the following declaration.

[[bin]]
name = "status_processor"
path = "src/bin/daas-status-processing.rs"

This will tell Cargo that there is a binary file to be compiled and to name the exeutable status_processor.

Coding the Executable

Let's begin by creating a file named daas-status-processing.rs in the src/bin/ directory.

At the top of the file, we will start be declare the dependent crate with macros and the use statements.

We then define the module variables for this executable.

To make our work easier, we will utilize a StatusRecord object to handle the status data.

Next we need to provide the supportive function to handle updating the status history.

Now, we are ready to writ ethe main() function that will be called when the executable starts.

IMPORTANT

  • You will need to create a database named provisioning in CouchDB in order for this service to work.

  • You will need to create a topic named test in the Kafka broker in order for this unit tests to pass.

Try to rerun the cargo test command, and ensure that all the test pass.

Running the Microsservice

On the command line, run the cargo run --bin status_processor command to start the service. (Or open a new command terminal and start the service using the executable in the target/debug directory).

{ "_id": "history|status|iStore|8003", "_rev": "3-9b8f57b145ddfea0e3fec0147a6cb835", "source_name": "iStore", "source_uid": 8003, "category": "history", "subcategory": "status", "author": "istore_app", "process_ind": false, "last_updated": 1572027379, "data_obj": { "order_number": 8003, "order_status": [ { "name": "new", "timestamp": 1572021078 }, { "name": "new", "timestamp": 1572021537 }, { "name": "acknowledge", "timestamp": 1572027549 } ], "order_type": "clothing", "store_name": "iStore", "timestamp": 1572021078 } } ```

Last updated

Was this helpful?