Skip to content

A Simple Template for Effective Communication using NATS.io as Gateway and central Message Broker

Notifications You must be signed in to change notification settings

bowber/mottomesh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MottoMesh Template

A new way to communicate in my app (and yours).

Goals

  • Use most efficient data formats.
  • Use most efficient protocols.
  • Use most scalable technologies.
  • Browser front-end support (other front-end platforms will be considered later)
  • Rust Back-end (and binding to other languages later if needed)

Key Features

  • HTTP-like communication using Request-Reply mechanism of NATS
  • Bi-directional communication using Pub-Sub mechanism of NATS
  • Websocket (and NATS protocol for the server) with ease of scaling (by using NATS Cluster and Super Cluster)
  • Client-side load-balancing, Geo-Routing
  • Type-safe, compact, fast and easy Serialization/Deserialization with the combination of bitcode-rs and wasm-bindgen

How to use

Prerequisites

Export npm package

  • Generate the WASM npm package by running wasm-pack build
  • Publish built npm package to npm with wasm-pack publish
  • In case you don't want to publish, you can pack the built npm package with wasm-pack pack and publish it anywhere else (like a private registry).
  • See an example project in example_web, run it and open 2 browser tabs to see the communication in action.

Build server

  • Build the Rust server by running cargo build --release
  • The binary file will be located in target/release/
  • Or use cargo run for development

Tests

  • Test npm package on browser with wasm-pack test --chrome
  • Test Rust server with cargo test (there's no test for the server yet)

How was this template created? (So you can migrate existing projects)

  • Add bitcode, wasm-bindgen, async-nats as dependencies
  • Define TestData struct
  • Derive TestData struct with traits: bitcode::Decode, bitcode::Encode and wasm-bindgen
  • Implement TestData struct with #[wasm_bindgen]
  • Write tests in tests/web_tests.rs

Key dependencies

  • bitcode-rs: For serialization/deserialization
  • wasm-bindgen: For binding in the browser
  • NATS.io: For messaging and communication between services.
  • flate2: For compression and decompression

Not implemented yet

  • UniFFI: For Android and iOS bindings (do it later for more front-end platforms)
  • napi-rs: For Node.js bindings

About

A Simple Template for Effective Communication using NATS.io as Gateway and central Message Broker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published