The RMB Peer Client is a TypeScript library that enables communication with the ThreeFold Messaging Bus (RMB). It provides functionalities similar to the Rust client.
To use the RMB Peer Client, instantiate the MessageBusClient
class:
import { MessageBusClient } from "@threefold/rmb_peer_client";
const messageBus = new MessageBusClient();
You can send messages over the RMB using the send
method, which takes the following parameters:
-
requestCommand
The command to be executed in the Zero-OS node. -
requestData
The message content. -
destinationTwinId
The ID of the destination twin to receive the message. -
expirationMinutes
Expiration time for the message in minutes.
const requestId = await messageBus.send("zos.nodes.list", "", 143, 5);
After sending a message, you can read the response using the read
method:
const response = await messageBus.read(requestId);
Install the package via npm:
npm install @threefold/rmb_peer_client
import { MessageBusClient } from "@threefold/rmb_peer_client";
const messageBus = new MessageBusClient();
// Send a message
const requestId = await messageBus.send("zos.nodes.list", "", 143, 5);
// Read the response
const response = await messageBus.read(requestId);
- Constructor function to create a new instance of the RMB Peer Client.
- Accepts an optional
port
parameter to specify the Redis server port. Defaults to6379
.
send(requestCommand: string, requestData: string, destinationTwinId: number, expirationMinutes: number): Promise<string>
- Method to send a message over the RMB.
- Returns a promise that resolves to the request ID.
- Method to read the response for a specific request ID.
- Accepts an optional
timeoutMinutes
parameter to specify the timeout duration for waiting for the response. - Returns a promise that resolves to the response data.
- Redis server running locally or on a specified host/port.