Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

threefoldtecharchive/rmb-sdk-go

Repository files navigation

Go Documentation

Introduction

This is a GO sdk that can be used to build both services, and clients that can talk over the rmb.

RMB is a message bus that enable secure and reliable RPC calls across the globe.

RMB itself does not implement an RPC protocol, but just the secure and reliable messaging hence it's up to server and client to implement their own data format.

How it works

If two processes needed to communicate over RMB, they both need to have some sort of a connection to an rmb-relay.
This connection could be established using a direct-client, or an rmb-peer.

Direct client

A process could connect to an rmb-relay using a direct client.
To create a new direct client instance, a process needs to have:

  • A valid mnemonics, with an activated account on the TFChain.
  • The key type of these mnemonics.
  • A relay URL that the direct client will connect to.
  • A session id. This could be anything, but a twin must only have a unique session id per connection.
  • A substrate connection.

Example

Creating a new direct client instance:

subManager := substrate.NewManager("wss://tfchain.dev.grid.tf/ws")
sub, err := subManager.Substrate()
if err != nil {
    return fmt.Errorf("failed to connect to substrate: %w", err)
}

defer sub.Close()
client, err := direct.NewClient(direct.KeyTypeSr25519, mnemonics, "wss://relay.dev.grid.tf", "test-client", sub)
if err != nil {
    return fmt.Errorf("failed to create direct client: %w", err)
}

Assuming there is a remote calculator process that could add two integers, an rmb call using the direct client would look like this:

x := 1
y := 2
var sum int
err := client.Call(ctx, destinationTwinID, "calculator.add", []int{x, y}, &sum)

About

A go framework to build services/clients on top of RMB

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages