Skip to content

Commit

Permalink
Merge pull request #2679 from threefoldtech/development_rmb_docs
Browse files Browse the repository at this point in the history
Update installation instructions in RMB `Peer`, `Direct` README.md
  • Loading branch information
amiraabouhadid authored May 14, 2024
2 parents eebb938 + 0da074a commit 3bb13b1
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 13 deletions.
16 changes: 16 additions & 0 deletions packages/rmb_direct_client/DEVELOPERS.README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Types Update Guide for Developers

## Introduction

This guide outlines the steps to update the types used in the `RMB Direct Client` to reflect changes in messages sent over the RMB.

### Prerequisites

- **Install Protobuf**: Install [Protobuf](https://grpc.io/docs/protoc-installation/) on your system.

## Usage

1. **Update types.proto File**: Update the [types.proto](lib/types.proto) file with any changes to the message structure.
2. **Run build.sh Script**: Execute the [build.sh](build.sh) script to generate the necessary TypeScript files.

After updating the types, run the `build.sh` script, and ensure that the client is updated accordingly to utilize the auto-generated [types.ts](lib/types/lib/types.ts) file.
6 changes: 1 addition & 5 deletions packages/rmb_direct_client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,4 @@ yarn workspace @threefold/rmb_direct_client start
- Git
- Yarn

## Contributors

Contributions, issues, and feature requests are welcome!

Feel free to check the [issues page](https://github.com/threefoldtech/tfgrid-sdk-ts/issues).
To update the RMB Messages to a newer version refer to [DEVELOPER.README.md](DEVELOPERS.README.md) file.
2 changes: 1 addition & 1 deletion packages/rmb_direct_client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"npm-run-all": "^4.1.5",
"protoc-gen-ts": "^0.8.5",
"ts-node": "^10.9.1",
"typescript": "*"
"typescript": "^4.9"
},
"main": "./dist/node/index.js",
"module": "./dist/es6/index.js",
Expand Down
75 changes: 74 additions & 1 deletion packages/rmb_peer_client/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,78 @@
# rmb_peer_client
# RMB Peer Client

[![Version](https://img.shields.io/npm/v/@threefold/rmb_peer_client?color=blue)](https://www.npmjs.com/package/@threefold/rmb_peer_client)
[![Lint](https://github.com/threefoldtech/tfgrid-sdk-ts/actions/workflows/lint.yml/badge.svg)](https://github.com/threefoldtech/tfgrid-sdk-ts/actions/workflows/lint.yml)
[![Build](https://github.com/threefoldtech/tfgrid-sdk-ts/actions/workflows/build.yml/badge.svg)](https://github.com/threefoldtech/tfgrid-sdk-ts/actions/workflows/build.yml)

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](https://github.com/threefoldtech/rmb-rs).

## Usage

To use the RMB Peer Client, instantiate the `MessageBusClient` class:

```ts
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:

1. `requestCommand` The command to be executed in the Zero-OS node.
2. `requestData` The message content.
3. `destinationTwinId` The ID of the destination twin to receive the message.
4. `expirationMinutes` Expiration time for the message in minutes.

```ts
const requestId = await messageBus.send("zos.nodes.list", "", 143, 5);
```

After sending a message, you can read the response using the `read` method:

```ts
const response = await messageBus.read(requestId);
```

## Installation

Install the package via npm:

```bash
npm install @threefold/rmb_peer_client
```

## Example

```ts
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);
```

## API

### `MessageBusClient()`

- Constructor function to create a new instance of the RMB Peer Client.
- Accepts an optional `port` parameter to specify the Redis server port. Defaults to `6379`.

### `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.

### `read(requestId: string, timeoutMinutes = 1): Promise<unknown>`

- 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.

## Requirements

- Redis server running locally or on a specified host/port.
12 changes: 6 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13561,16 +13561,16 @@ typedoc@^0.23.28:
minimatch "^7.1.3"
shiki "^0.14.1"

typescript@*, typescript@^5.0.2:
version "5.0.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b"
integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==

"typescript@^3 || ^4", typescript@^4.7.4, typescript@^4.8.4, typescript@^4.9.3:
"typescript@^3 || ^4", typescript@^4.7.4, typescript@^4.8.4, typescript@^4.9, typescript@^4.9.3:
version "4.9.5"
resolved "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz"
integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==

typescript@^5.0.2:
version "5.0.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b"
integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==

typescript@^5.3.3:
version "5.3.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.3.3.tgz#b3ce6ba258e72e6305ba66f5c9b452aaee3ffe37"
Expand Down

0 comments on commit 3bb13b1

Please sign in to comment.