- Start the cluster
- Showcase: LlamaDB SQL database running on Fluence
- Showcase: ToDo-list backed by LlamaDB and Fluence
- Stop the cluster
Welcome to the Fluence workshop at the Web3Summit (Oct, 2018)
We will demonstrate the core of the Fluence platform and show how developers can use it to set up an infrastructure for the real-time data processing in decentralized environment.
At the workshop you will:
Learn about the nature of Fluence: the architecture overview and roadmap, the Fluence network, its composition, and how a developer could use it to power up a serverless application.
Have your own experience:
- set up a local Fluence cluster,
- launch a legacy SQL database (written in Rust) inside it,
- test it: store and load data by running SQL queries in web browser,
- implement a persistence layer in a simple web app (ToDo list) using Fluence js client.
This document will guide you through the process step-by-step. If you’ve discovered any bugs or faced difficulties replicating the results, please, feel free to poke us on Gitter!
All you need is an installed npm and Docker.
You can get Docker for your platform here:
macOS users, kindly note that
brew install docker is not enough, you will also need a Docker daemon. To install: download, open, copy Docker.app to Applications and run Docker.app from the Applications folder.
Start the cluster
Clone this repo by executing
git clone https://github.com/fluencelabs/workshop-2018-oct
In terminal, go to the
workshop-2018-oct folder and launch the cluster by running
or, depending on your OS and Docker settings, you may need to use
sudo as in
this will run 4 docker containers listening for client connections on the ports
Fluence keys, configuration and working directories are placed to
LlamaDB SQL database running on FluenceShowcase:
sql-client/index.htmlfile in the web browser.
- You can see cluster nodes statuses on the left, like this:
- Copy all queries from the
Example queriesblock to the
- Push the
- Wait for the result in the
- You can see logs of what's happening in the web console:
Showcase: ToDo-list backed by LlamaDB and Fluence
We've seen Fluence run LlamaDB and execute plain SQL queries, now it's time to apply that knowledge to an actual web application.
- Go to
index.htmlfile in the web browser.
You can see a TODO list app where you can add tasks, flag them as
done and delete them.
But there is no persistence! All tasks will be gone after a page reload :(
Let's fix it!
- Open terminal and go to
npm install firstname.lastname@example.org.
index.htmlin your favorite browser or reload if it was already open.
- Open web console in the browser. (also called Developer Tools in Chrome)
- To create session for interaction with the cluster, enter in web console:
let session = fluence.createDefaultSession("localhost", 25057);
- To create a table in the database, enter in web console:
session.invoke("do_query", "CREATE TABLE TODO_LIST(task varchar(128))");
- Add some tasks with an SQL command. To get the query result you can use
result()method that will return promise. Enter in web console:
let result = session.invoke("do_query", "INSERT INTO TODO_LIST VALUES ('Fly to the moon'),( 'Conquer the world')").result();
asString()will convert the result from bytes to string:
result.then((result) => console.log(result.asString()))
- Reload the page, new tasks will be available.
Implement persistence layer in ToDo app
index.jsin your favorite text editor.
- Navigate to the
- That's the function called on the press of the
- We have already prepared function
addTaskToFluencethat sends task to Fluence when you press Add button. It works by sending an INSERT statement like we just did in the Web Console. Let's uncomment call to that function so the tasks are persisted on creation:
- Navigate to
function completeTask()and uncomment calls to
addTaskToFluence, so tasks completion would also be persisted:
deleteFromFluence(task, todo_table); addTaskToFluence(task, done_table);
npm installto install webpack.
npm run build.
index.htmlin web browser.
- Now you can add tasks through interface and they will be persisted!
Stop the cluster
You can stop running Fluence nodes by going to the workshop directory
workshop-2018-oct and running
To cleanup Fluence local files, remove
rm -rf $HOME/.fluence