Skip to content

Latest commit

 

History

History

order

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

WasmEdge ETL function example

Prerequisites

On Linux, you can use the following commands to install Rust and WasmEdge.

# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
# Install WebAssembly target for Rust
rustup target add wasm32-wasi

# Install WasmEdge
curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -e all
source $HOME/.wasmedge/env

Build

Use the following command to build the microservice. A WebAssembly bytecode file (wasm file) will be created.

cargo build --target wasm32-wasi --release

You can run the AOT compiler on the wasm file. It could significantly improvement the performance.

wasmedgec target/wasm32-wasi/release/order.wasm order.wasm

Run

You can use the wasmedge command to run the wasm application. It will start the server. Make sure that you pass the DATABASE_URL that points to your running MySQL server.

nohup wasmedge --env "DATABASE_URL=mysql://user:[email protected]:3306/mysql" order.wasm 2>&1 &

The server log will appear in the nohup.out file.

See it in action

You can send data to the webhook using curl.

curl http://localhost:3344/ -X POST -d @order.json

You can now log into the database to see the orders table and its content.

Docker

With WasmEdge support in Docker, you can also use Docker Compose to build and start this multi-container application in a single command without installing any dependencies.

Then, you just need to type one command.

docker compose up

This will build the Rust source code, run the Wasm server for the ETL function, and startup a MySQL backing database. You can then use the curl commands to send data to the webhook for the ETL.

To see the data in the database container, you can use the following commands.

docker compose exec db /bin/bash 
root@c97c472db02e:/# mysql -u root -pwhalehello mysql
mysql> select * from orders;
... ...