Skip to main content
Version: 0.13.0 (stable)

Make Uppercase (map)

Create a SmartModule that converts records to uppercase.

Prerequisitesโ€‹

  • SDMK CLI is part of the Fluvio installation. Install Fluvio and start a local a cluster to build and test the SmartModule.

Generate a Smartmodule Projectโ€‹

Use SMDK generator to create a new SmartModule project of type map.

$ smdk generate uppercase
๐Ÿคท Please set a group name: acme
โœ” ๐Ÿคท Which type of SmartModule would you like? ยท map
โœ” ๐Ÿคท Will your SmartModule use init parameters? ยท false
โœ” ๐Ÿคท Will your SmartModule be public? ยท false
[1/7] Done: .gitignore
[2/7] Done: Cargo.toml
[3/7] Done: README.md
[4/7] Done: SmartModule.toml
[5/7] Done: rust-toolchain.toml
[6/7] Done: src/lib.rss
[7/7] Done: src

Add Custom logicโ€‹

Let's checkout the project tree:

$ cd uppercase; tree
.
โ”œโ”€โ”€ Cargo.toml
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ SmartModule.toml
โ”œโ”€โ”€ rust-toolchain.toml
โ””โ”€โ”€ src
โ””โ”€โ”€ lib.rs

Replace the existing code in src/lib.rs with the following:

use fluvio_smartmodule::{smartmodule, Result, SmartModuleRecord, RecordData};

#[smartmodule(map)]
pub fn map(record: &SmartModuleRecord) -> Result<(Option<RecordData>, RecordData)> {
let key = record.key.clone();

let string = std::str::from_utf8(record.value.as_ref())?;
let upper = string.to_string().to_uppercase();

Ok((key, upper.into()))
}

Build and Testโ€‹

It's time to build the SmartModule:

$ smdk build

Test the SmartModule:

$ smdk test --text "Hello in uppercase"
HELLO IN UPPERCASE

Load Smartmodule to your Clusterโ€‹

You must upload the SmartModule to your cluster to use it.

$ smdk load
Creating SmartModule: uppercase

Ensure it has been uploaded by running the following command:

$ fluvio sm list
SMARTMODULE SIZE
acme/uppercase@0.1.0 40.9 KB

๐ŸŽ‰ Congratulations! Your smartmodule is ready to use.