mirror of
https://github.com/fluencelabs/gitbook-docs
synced 2025-04-25 07:52:14 +00:00
GitBook: [2.0.0] 4 pages modified
This commit is contained in:
parent
48572e1005
commit
617c3d3cd5
@ -17,13 +17,13 @@ npm start
|
||||
|
||||
Which opens a new tab in your browser at `http://localhost:3000`. Depending on your VSCode settings, you may have to confirm your choice.
|
||||
|
||||
The browser tab, representing the client peer, wants you to pick a relay node the browser client can connected to and, of course, allows the peer to respond to the browser client. Select any one of the offered relays:
|
||||
The browser tab, representing the client peer, wants you to pick a relay node the browser client can connect to and, of course, allows the peer to respond to the browser client. Select any one of the offered relays:
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
The client peer is now connected to the relay and and ready for business:
|
||||
The client peer is now connected to the relay and ready for business:
|
||||
|
||||

|
||||
|
||||
@ -32,7 +32,7 @@ Let's follow the instructions, open another browser tab, i.e. client peer, using
|
||||
|
||||

|
||||
|
||||
Congratulations, you just sent messages between two browsers over the Fluence peer-to-peer network, which is pretty cool ! Even cooler, however, is how we got here using Aqua, Fluence's distributed network and application composition language.
|
||||
Congratulations, you just sent messages between two browsers over the Fluence peer-to-peer network, which is pretty cool! Even cooler, however, is how we got here using Aqua, Fluence's distributed network and application composition language.
|
||||
|
||||
In your VSCode workspace, navigate to the `aqua` directory and open the \``getting-started.aqua` file in VSCode:
|
||||
|
||||
@ -44,7 +44,7 @@ In broad strokes, the Aqua code breaks down as follows:
|
||||
|
||||
* Import the Aqua [standard library](https://github.com/fluencelabs/aqua-lib) into our application \(1\)
|
||||
* Create a service interface binding to the local service \(see below\) with the `HelloPeer` namespace and `hello` function \(4-5\)
|
||||
* Create the composition function `sayHello` that executes the `hello` call on the provided `targetPeerId` via the provided `targetRelayPeerId` and returns the result \(7-10\). Recall the copy and paste job you did earlier in the browser tab for the peer and relay id ? Well, you just found the consumption place for these two parameters.
|
||||
* Create the composition function `sayHello` that executes the `hello` call on the provided `targetPeerId` via the provided `targetRelayPeerId` and returns the result \(7-10\). Recall the copy and paste job you did earlier in the browser tab for the peer and relay id? Well, you just found the consumption place for these two parameters.
|
||||
|
||||
Not only is Aqua rather succinct in allowing you to seamlessly program both network routes and distributed application workflows but also provides the ability to compile Aqua to Typescript stubs wrapping compiled Aqua, called AIR -- short for Aqua Intermediate Representation, into ready to use code blocks. Navigate to the `src/_aqua` directory and open the `getting-started.ts` file in VSCode:
|
||||
|
||||
@ -54,7 +54,7 @@ Which can now be imported into our `App.tsx` file:
|
||||
|
||||

|
||||
|
||||
Lest it be overlooked, we wrote a little more than a handful of lines of code in Aqua and ended up with a deployment ready code block that includes both the network routing and compute logic to facilitate browser-to-browser messaging over a peer-to-peer network.
|
||||
Lest it be overlooked, we wrote a little more than a handful of lines of code in Aqua and ended up with a deployment-ready code block that includes both the network routing and a compute logic to facilitate browser-to-browser messaging over a peer-to-peer network.
|
||||
|
||||
The local \(browser\) service `HelloPeer` is also implemented in the `App.tsx` file:
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# 2. Hosted Services
|
||||
|
||||
In the previous example we used a local, browser-native service to facilitate the string generation and communication with another browser. The real power of the Fluence solution, however, is that services can be hosted one one or more nodes, easily reused and composed into decentralized applications with Aqua.
|
||||
In the previous example, we used a local, browser-native service to facilitate the string generation and communication with another browser. The real power of the Fluence solution, however, is that services can be hosted on one or more nodes, easily reused and composed into decentralized applications with Aqua.
|
||||
|
||||
### Creating A Wasm Module
|
||||
|
||||
@ -10,7 +10,7 @@ In this section, we develop a simple `HelloWorld` service and host it on a peer-
|
||||
|
||||
Fluence hosted services are comprised of WebAssembly modules implemented in Rust and compiled to [wasm32-wasi](https://doc.rust-lang.org/stable/nightly-rustc/rustc_target/spec/wasm32_wasi/index.html). Let's have look at our code:
|
||||
|
||||
```text
|
||||
```rust
|
||||
// quickstart/2-hosted-services/src/main.rs
|
||||
use marine_rs_sdk::marine;
|
||||
use marine_rs_sdk::module_manifest;
|
||||
@ -44,7 +44,7 @@ Aside from some housekeeping, the `build.sh` script gives the compile instructio
|
||||
|
||||
So far, so good. Of course, we want to test our code and we have a couple of test functions in our `main.rs` file:
|
||||
|
||||
```text
|
||||
```rust
|
||||
// quickstart/2-hosted-services/src/main.rs
|
||||
use marine_rs_sdk::marine;
|
||||
use marine_rs_sdk::module_manifest;
|
||||
@ -71,7 +71,7 @@ mod tests {
|
||||
```
|
||||
|
||||
|
||||
To run our tests, we can use the familiar[`cargo test`](https://doc.rust-lang.org/cargo/commands/cargo-test.html) . However, we don't really care all that much about our native Rust functions being tested but want to test our WebAssembly functions. This is where the extra code in the test module comes into play. In short., we are running `cargo test` against the exposed interfaces of the `hello_world.wasm` module and in order to do that, we need the `marine_test` macro and provide it with both the modules directory, i.e., the `artifacts` directory, and the location of the `Config.toml` file. Note that the `Config.toml` file specifies the module meta data and optional module linking data. Moreover, we need to call our Wasm functions from the module namespace, i.e. `hello_world.hello` instead of the standard `hello` -- see lines 13 and 19 above.
|
||||
To run our tests, we can use the familiar[`cargo test`](https://doc.rust-lang.org/cargo/commands/cargo-test.html) . However, we don't really care all that much about our native Rust functions being tested but want to test our WebAssembly functions. This is where the extra code in the test module comes into play. In short., we are running `cargo test` against the exposed interfaces of the `hello_world.wasm` module and in order to do that, we need the `marine_test` macro and provide it with both the modules directory, i.e., the `artifacts` directory, and the location of the `Config.toml` file. Note that the `Config.toml` file specifies the module metadata and optional module linking data. Moreover, we need to call our Wasm functions from the module namespace, i.e. `hello_world.hello` instead of the standard `hello` -- see lines 13 and 19 above.
|
||||
|
||||
From the VSCode terminal, we now run our tests with the`cargo +nightly test --release` command. Please note that if `nightly` is your default, you don't need it in your `cargo test` command.
|
||||
|
||||
@ -85,7 +85,7 @@ mrepl configs/Config.toml
|
||||
|
||||
which puts us in the REPL:
|
||||
|
||||
```text
|
||||
```bash
|
||||
Welcome to the Marine REPL (version 0.8.0)
|
||||
Minimal supported versions
|
||||
sdk: 0.6.0
|
||||
@ -125,7 +125,7 @@ marine aqua artifacts/hello_world.wasm
|
||||
|
||||
Which gives us the Aqua-ready interfaces:
|
||||
|
||||
```text
|
||||
```haskell
|
||||
data HelloWorld:
|
||||
msg: string
|
||||
reply: string
|
||||
@ -162,7 +162,7 @@ Which gets us a list of network peers:
|
||||
|
||||
Let's use the peer`12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi` as our deployment target and deploy our service from the VSCode terminal. In the `quickstart/2-hosted-services` directory run:
|
||||
|
||||
```text
|
||||
```bash
|
||||
fldist --node-id 12D3KooWFEwNWcHqi9rtsmDhsYcDbRUCDXH84RC4FW6UfsFWaoHi \
|
||||
new_service \
|
||||
--ms artifacts/hello_world.wasm:configs/hello_world_cfg.json \
|
||||
@ -176,7 +176,7 @@ service id: 1e740ce4-81f6-4dd4-9bed-8d86e9c2fa50
|
||||
service created successfully
|
||||
```
|
||||
|
||||
Take note of the service id, `1e740ce4-81f6-4dd4-9bed-8d86e9c2fa50` in this examples but different for you, as we need it to use the service with Aqua.
|
||||
Take note of the service id, `1e740ce4-81f6-4dd4-9bed-8d86e9c2fa50` in this example but different for you, as we need it to use the service with Aqua.
|
||||
|
||||
Congratulations, we just deployed our first reusable service to the Fluence network and we can admire our handiwork on the Fluence [Developer Hub](https://dash.fluence.dev/):
|
||||
|
||||
|
@ -14,17 +14,17 @@ And run the application with:
|
||||
npm start
|
||||
```
|
||||
|
||||
Which will open a new browser tab at `http://localhost:3000` . Following the instructions we connect to any one of the displayed relay ids, open another browser tab also at `http://localhost:3000`, select a relay and copy and paste the client peer id and relay id into corresponding fields in the first tab and press the `say hello` button.
|
||||
Which will open a new browser tab at `http://localhost:3000` . Following the instructions, we connect to any one of the displayed relay ids, open another browser tab also at `http://localhost:3000`, select a relay and copy and paste the client peer id and relay id into corresponding fields in the first tab and press the `say hello` button.
|
||||
|
||||

|
||||
|
||||
The result looks familiar, so what's different ? Let's have a look at the Aqua file. Navigate to the `aqua/getting_started.aqua` file in your IDE:
|
||||
The result looks familiar, so what's different? Let's have a look at the Aqua file. Navigate to the `aqua/getting_started.aqua` file in your IDE:
|
||||
|
||||

|
||||
|
||||
And let's work it from the top:
|
||||
|
||||
* Import the the Aqua standard library \(1\)
|
||||
* Import the Aqua standard library \(1\)
|
||||
* Provide the hosted service peer id \(3\) and service id \(4\)
|
||||
* Specify the `HelloWorld` struct interface binding \(6-8\) for the hosted service from the `marine aqua` export
|
||||
* Specify the `HelloWorld` interface and function binding \(11-12\) for the hosted service from the `marine aqua` export
|
||||
@ -41,5 +41,5 @@ Before we dive into the `sayHelo` function, let's look at why we still need a lo
|
||||
|
||||
A little more involved than our first example but we are again getting a lot done with very little code. Of course, there could be more than one hosted service in play and we could implement, for example, hosted spell checking, text formatting and so much more without much extra effort to express additional workflow logic in our Aqua script.
|
||||
|
||||
This brings us to the end of this quick start tutorial. We hope you are as exited as we are to put Aqua and the Fluence stack to work. To continue your Fluence journey, have a look at the remainder of this book, take a deep dive into Aqua with the [Aqua book](https://doc.fluence.dev/aqua-book/) or dig into Marine and Aqua examples in the [repo](https://github.com/fluencelabs/examples).
|
||||
This brings us to the end of this quick start tutorial. We hope you are as excited as we are to put Aqua and the Fluence stack to work. To continue your Fluence journey, have a look at the remainder of this book, take a deep dive into Aqua with the [Aqua book](https://doc.fluence.dev/aqua-book/) or dig into Marine and Aqua examples in the [repo](https://github.com/fluencelabs/examples).
|
||||
|
||||
|
@ -4,7 +4,7 @@ Welcome to our quick-start tutorials which guide you through the necessary steps
|
||||
|
||||
1. Create a browser-to-browser messaging web application
|
||||
2. Create and deploy a hosted service
|
||||
3. Create a browser-to-service messaging web application
|
||||
3. Enhance a browser-to-browser application with a network-hosted service
|
||||
|
||||
For your development convenience, Fluence provides a [docker-based development environment](https://github.com/fluencelabs/devcontainer) that comes with the necessary dependencies, tooling and quick-start code pre-installed.
|
||||
|
||||
@ -19,7 +19,7 @@ Fluence's devcontainer is a ready to use dockerized development environment with
|
||||
|
||||
### How to install
|
||||
|
||||
Docker and optionally VSCode need to be available on your system. For Docker installation, follow the [Get Docker](https://docs.docker.com/get-docker/) instructions for your OS. For VSCode, see [VSCocde](https://code.visualstudio.com/) for instructions.
|
||||
Docker and optionally VSCode need to be available on your system. For Docker installation, follow the [Get Docker](https://docs.docker.com/get-docker/) instructions for your OS. For VSCode, see [VSCode](https://code.visualstudio.com/) for instructions.
|
||||
|
||||
With Docker and VSCode in place:
|
||||
|
||||
@ -47,3 +47,5 @@ Congratulations, you now have a fully functional Fluence development environment
|
||||
|
||||
If you encounter any problems or have suggestions, please open an issue or submit a PR. You can also reach out in [Discord](https://fluence.chat) or [Telegram](https://t.me/fluence_project). For more detailed reference resources, see the [Fluence documentation](https://doc.fluence.dev/docs/) and [Aqua book](https://doc.fluence.dev/aqua-book/).
|
||||
|
||||
All right, now we are ready to proceed to the first application on Fluence.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user