Skip to main content
Version: 0.13.0 (stable)

Generate

SMDK generate helps developers build a sample SmartModule project by answering a few simple questions.

Generate - Operationโ€‹

SMDK generate commands runs a wizard and builds a sample project in a subdirectory

$ smdk generate my-filter

Generating new SmartModule project: my-filter
fluvio-smartmodule-cargo-dependency => '"0.2.5"'
๐Ÿ”ง Destination: ~/smdk/my-filter ...
๐Ÿ”ง Generating template ...
๐Ÿคท Will your SmartModule use init parameters? ยท false
๐Ÿคท Which type of SmartModule would you like? ยท filter
๐Ÿคท Will your SmartModule be public? ยท false
๐Ÿคท Please set a group name : acme
[1/5] Done: Cargo.toml
[2/5] Done: README.md
[3/5] Done: SmartModule.toml
[4/5] Done: src/lib.rs
[5/5] Done: src
๐Ÿ”ง Moving generated files into: `~/smdk/my-filter`...
๐Ÿ’ก Initializing a fresh Git repository
โœจ Done! New project created ~/smdk/my-filter
hub: hubid acme is set

The generator created Rust project ready to compile:

$ tree
.
โ”œโ”€โ”€ Cargo.toml
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ SmartModule.toml
โ””โ”€โ”€ src
โ””โ”€โ”€ lib.rs

This is a simple SmartModule filter matching for all data records that contains letter a:

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

#[smartmodule(filter)]
pub fn filter(record: &SmartModuleRecord) -> Result<bool> {
let string = std::str::from_utf8(record.value.as_ref())?;
Ok(string.contains('a'))
}

Note the SmartModule.toml file. This file contains SmartModule parameters required to load the file in the Cluster and publish it to SmartModule Hub.

$ cat SmartModule.toml

[package]
name = "my-filter"
group = "acme"
version = "0.1.0"
apiVersion = "0.1.0"
description = ""
license = "Apache-2.0"

[[params]]
name = "input"
description = "input description"

Sectionsโ€‹

  • package is used to build the SmartModule FQDN acme/my-filter@0.1.0, and the description to publish to SmartModule Hub. The group name is equivalent to the package owner in the Hub.
  • params defines the command line parameters by the SmartModule internal logic.

The project is ready to build and test. Checkout the next section for instructions.

Stepsโ€‹

  1. Generate a SmartModule
  2. Build and Test
  3. Load to your Cluster
  4. Publish to SmartModule Hub