Skip to content
Felix Bole edited this page Mar 20, 2025 · 1 revision

Usage Example Based on the available LiteConnector

Setting up a Chain

Deploy a chain using NodeSupervisor.

const chainConfig = [
  { services: [], location: 'local', monitoringHost: 'http://localhost:8887/' },
  { services: ['http://localhost:8888/service1'], location: 'remote' }
];
const data = { hello: 'here the data' };
const supervisor = NodeSupervisor.retrieveService();
const chainId = await supervisor.handleRequest({
  signal: 'chain_deploy',
  config: chainConfig,
  data
});

Starting a Chain

Start a deployed chain using its chainId.

await supervisor.handleRequest({
  signal: 'chain_start',
  id: chainId,
  data
});

Handling Node Signals

Control nodes with signals like suspend or resume.

  • Suspend a Node:

    {
      "hostURI": "http://localhost:8888/",
      "chainId": "your-chain-id",
      "targetId": "http://localhost:8888/service1"
    }

    Send to POST /node/suspend on the connector.

  • Resume a Node: Use POST /node/resume with a similar payload.


Using the LiteConnector

The LiteConnector is a test tool for the library.

  • Start the Server:

    const connector = new LiteConnector(8887, 'connector1');
    await connector.startServer();
  • Create and Start a Chain: Use POST /chain/create-and-start:

    {
      "chainConfig": [
        { "services": [], "location": "local", "monitoringHost": "http://localhost:8887/" },
        { "services": ["http://localhost:8888/service1"], "location": "remote" }
      ],
      "data": { "hello": "here the data" }
    }
  • Endpoints:

    • /node/resume: Resume a node.
    • /node/suspend: Suspend a node.
    • /node/communicate/:type: Handle setup, run, or notify actions.

Test it

Starting 4 Test Connectors

node ./launch-connectors.js

Create and Start a Chain

Endpoint: POST http://localhost:8887/chain/create-and-start

This endpoint allows you to configure and start a chain in a single request.

Payload Examples

Example 1: With metadata, resolver, and configuration

{
  "chainConfig": [
    {
      "services": [],
      "location": "local",
      "monitoringHost": "http://localhost:8887/"
    },
    {
      "services": [{"targetId": "service1", "meta":{"resolver": "http://localhost:8888/", "configuration":{"a": "some configuration"}}}],
      "location": "remote"
    }
  ],
  "data": {
      "hello": "here the data"
   }
}

see more

LiteConnector Example Usage for Parallel Node execution

Start 4 Test Connectors

node ./launch-connectors.js --type 1

Endpoint to create the chain across all connectors

POST: http://localhost:8887/chain/create-and-start

*Payload Example parallel, with meta data, resolver and configuration:

{
  "chainConfig": [
    {
      "services": [],
      "location": "local",
      "monitoringHost": "http://localhost:8887/",
      "childMode": "parallel", // possible values "normal", "parallel", "undefined"
      "chainConfig": [
        {
          "services": [{"targetId": "service_0_0"}],
          "location": "local",
          "monitoringHost": "http://localhost:8888/"
        }
      ]
    },
    {
      "chainConfig": [
        {
          "services": [{
            "targetId": "service_1_0",
            "meta": {
              "configuration": {
                "a": "some configuration"
              }
            }
          }],
          "location": "local",
          "childMode": "normal", // "normal" same as if it was "undefined"
          "monitoringHost": "http://localhost:8889/"
        }
      ],
      "location": "remote"
    }
  ],
  "data": {
      "hello": "here the input data"
   }
}

Clone this wiki locally