SMDK - Generate a SmartModule
SMDK generate helps developers build a sample SmartModule project by answering a few simple questions
Prerequisites
This section assumes that SMDK is installed
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 : aj
Ignoring: /var/folders/5q/jwc86771549058kmbkbqjcdc0000gn/T/.tmpwXs6cl/cargo-generate.toml
[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 aj 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 = "aj"
version = "0.1.0"
apiVersion = "0.1.0"
description = ""
license = "Apache-2.0"
[[params]]
name = "input"
description = "input description"
package
is used to build the SmartModule FQDNaj/my-filter@0.1.0
, and the description to publish to SmartModule Hub. Thegroup
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.