Generate
CDK generate helps developers build a sample SmartConnector project by answering a few simple questions. Prerequisites
This section assumes that CDK is installed.
Use cdk generate to create a new connector project:
$ cdk generate
๐คท Project Name: my-connector
๐ง Destination: ~/my-connector ...
๐ง project-name: my-connector ...
๐ง Generating template ...
โ ๐คท Will your Connector be public? ยท false
๐คท Please set a group name: aj
โ ๐คท Which type of Connector would you like [source/sink]? ยท source
Ignoring: /var/folders/r8/4x6_d2rn283946frzd1gc1pr0000gn/T/.tmptToFV3/cargo-generate.toml
[1/6] Done: Cargo.toml
[2/6] Done: Connector.toml
[3/6] Done: sample-config.yaml
[4/6] Done: src/config.rs
[5/6] Done: src/main.rs
[6/6] Done: src
๐ง Moving generated files into: `~/my-connector`...
๐ก Initializing a fresh Git repository
โจ Done! New project created ~/my-connector
The generator created Rust project ready to compile:
$ tree
.
โโโ Cargo.toml
โโโ Connector.toml
โโโ sample-config.yaml
โโโ src
โโโ config.rs
โโโ main.rs
2 directories, 5 files
This is a simple SmartConnector my-connector:
mod config;
use config::CustomConfig;
use fluvio::{RecordKey, TopicProducer};
use fluvio_connector_common::{
connector,
Result
};
#[connector(source)]
async fn start(config: CustomConfig, producer: TopicProducer) -> Result<()> {
println!("Starting my-connector source connector with {config:?}");
for i in 1..1000 {
let value = format!("Hello, Fluvio - {i}");
producer.send(RecordKey::NULL, value).await?;
producer.flush().await?;
std::thread::sleep(std::time::Duration::from_millis(1000));
}
Ok(())
}
Note the Connector.toml file. This file contains Connector parameters required to load the file in the Cluster and publish it to SmartConnector Hub.
$ cat Connector.toml
[package]
name = "my-connector"
group = "aj"
version = "0.1.0"
apiVersion = "0.1.0"
fluvio = "0.10.0"
description = ""
license = "Apache-2.0"
visibility = "private"
[direction]
source = true
[deployment]
binary = "my-connector"
[custom.properties.foo]
title = "Foo"
description = "Foo"
type = "string"
packageis used to build the SmartConnector FQDNaj/my-connector@0.1.0, and the description to publish to Hub. Thegroupname is equivalent to the package owner in the Hub.directionis used to declare the direction data flows through the connector, with respect to the Fluvio cluster. An inbound connector usessource = true, and and outbound connectdor usessink = truedeploymentcustom.properties.foodefines a user configuration keyfoothat can be used in the logic of the connector.
The project is ready to build and test. Checkout the next section for instructions.