Welcome to the Nexus! This README will guide you through setting up your development environment and getting started with the project.
Before you begin, make sure you have the following installed on your system:
- Nix
- Git
- Rust
- wasm32-unknown-unknown target
- OpenSSL 1.1
- Cosmoonic
- Clone the repository and navigate to the project directory:
git clone https://github.com/plurigrid/nexus.git
cd nexus
- Start nix shell and run the following command to install all required dependencies:
nix-shell
make all
This will automatically check for and install Rust, wasm32-unknown-unknown target, OpenSSL 1.1, and Cosmo CLI if they are not already installed on your system.
- Create a new actor using Cosmo CLI:
cosmo new actor <your_project_name>
Replace <your_project_name>
with your desired project name.
- Navigate to your newly created project directory:
cd <your_project_name>
- Edit
src/lib.rs
file in your favorite text editor.
The default file content looks like this:
use wasmbus_rpc::actor::prelude::*;
use wasmcloud_interface_httpserver::{HttpRequest, HttpResponse, HttpServer, HttpServerReceiver};
#[derive(Debug, Default, Actor, HealthResponder)]
#[services(Actor, HttpServer)]
struct <your_project_name>Actor {}
/// Implementation of the HttpServer capability contract
#[async_trait]
impl HttpServer for <your_project_name>Actor {
async fn handle_request(&self, _ctx: &Context, _req: &HttpRequest) -> RpcResult<HttpResponse> {
Ok(HttpResponse::ok("message"))
}
}
You can modify the file to accommodate more text like this:
use wasmbus_rpc::actor::prelude::*;
use wasmcloud_interface_httpserver::{HttpRequest, HttpResponse, HttpServer, HttpServerReceiver};
#[derive(Debug, Default, Actor, HealthResponder)]
#[services(Actor, HttpServer)]
struct <your_project_name>Actor {}
/// Implementation of the HTTP server capability
#[async_trait]
impl HttpServer for <your_project_name>Actor {
async fn handle_request(&self, _ctx: &Context, _req: &HttpRequest) -> RpcResult<HttpResponse> {
let message: &str = r#"message"#;
Ok(HttpResponse::ok(message))
}
}
- Login to Cosmonic:
cosmo login
- Build and sign your actor:
cosmo build
- Start your wasmCloud host:
cosmo up
- Launch the actor using Cosmo CLI:
cosmo launch
-
Navigate to Cosmonic App and sign in with your account.
-
In the Logic view, you should see the new actor you just launched.
-
To make your actor accessible from the web, launch a new provider for an HTTP server with the following OCI URL:
cosmonic.azurecr.io/httpserver_wormhole:0.5.3
. Give the link a name, and note that the HTTP server must be launched on a Cosmonic Manager resource. -
Once the HTTP server is launched, link it to your actor.
-
Launch a wormhole and connect it to your actor link (the HTTP server and the actor).
-
Your actor should now be accessible at the domain of the wormhole followed by
.cosmonic.app
. For example:https://white-morning-5041.cosmonic.app
.
Now you can access your project from any web browser using the provided URL!
You're all set! You can start building your project and explore the Nexus repository. Happy coding!
To send peer to peer pub-sub messages NATS is an excellent tool. This will walk you through setting up a NATS server and client to publish and subscribe to messages and expose your server using ngrok.
Start the NATS server by running the following command:
nats-server
-
Sign up for an account and download ngrok from the official website.
-
Follow the ngrok getting started guide to set up ngrok on your system.
-
Go to the ngrok dashboard to get your auth token.
-
Set your auth token with the following command:
ngrok config add-authtoken <auth_token>
-
Connect ngrok to your NATS server over TCP with the following command:
ngrok tcp 4222
-
ngrok will provide you with a URL that looks like this:
tcp://8.tcp.ngrok.io:13164
. You can use this URL to connect to your NATS server with the NATS client.
-
To subscribe to messages, run the following command:
nats sub -s <ngrok_tcp_url>
-
To publish a message, run the following command:
nats pub <subject> <body>
That's it! You have now set up a NATS server and client, and you can publish and subscribe to messages using the NATS CLI.