Neonatal Penguin March

    This package has been deprecated

    Author message:

    Please use @liteflow/orchestrator

    @mesg/application
    TypeScript icon, indicating that this package has built-in type declarations

    0.2.1 • Public • Published

    @mesg/application

    Website - Docs - Forum - Chat - Blog

    This library lets you connect to the MESG engine to listen for any event or result that you might be interested too. It also allows you to execute a task, either synchronously or asynchronously.

    Contents

    Installation

    npm install @mesg/application

    Application

    Require mesg-js as an application:

    const Application = require('@mesg/application')
    
    const mesg = new Application()

    MESG Engine endpoint

    By default, the library connects to the MESG Engine from the endpoint localhost:50052.

    Resolve SID

    Instead of hard-coding runnerHash in your application's env, your application can resolve dynamically using the service's SID.

    const runnerHash = await mesg.resolveRunner('SID_OF_THE_SERVICE')
    
    const result = await mesg.executeTaskAndWaitResult({
      executorHash: runnerHash,
      .....
    })

    Listen events

    Listen events from a service.

    const instanceHash = await mesg.resolve('SID_OF_THE_SERVICE')
    
    mesg.listenEvent({
      filter: {
        instanceHash: instanceHash,
        key: 'EVENT_KEY' // optional
      }
    })
    .on('data', (event) => {
      console.log('an event received:', event.key, mesg.decodeData(event.data))
    })

    Listen results

    Listen results from a service.

    const runnerHash = await mesg.resolveRunner('SID_OF_THE_SERVICE')
    
    mesg.listenResult({
      filter: {
        executorHash: runnerHash,
        taskKey: 'TASK_KEY_FILTER', // optional
        tags: ['TAG_FILTER'] // optional
      }
    })
    .on('data', (result) => {
      if (result.error) {
        console.error('an error has occurred:', result.error)
        return
      }
      console.log('a result received:', mesg.decodeData(result.outputs))
    })

    Execute task

    Execute task on a service.

    const runnerHash = await mesg.resolveRunner('SID_OF_THE_SERVICE')
    
    const execution = await mesg.executeTask({
      executorHash: runnerHash,
      eventHash: event.hash,
      taskKey: 'TASK_KEY',
      inputs: mesg.encodeData({ key: 'INPUT_DATA' }),
      tags: ['ASSOCIATE_TAG'] // optional
    })
    console.log('task in progress with execution:', execution.hash)

    Execute task and wait result

    Execute task on a service and wait for its result. This can be considered as a shortcut for using both executeTask() and listenResult() at same time.

    const runnerHash = await mesg.resolveRunner('SID_OF_THE_SERVICE')
    
    const result = await mesg.executeTaskAndWaitResult({
      executorHash: runnerHash,
      eventHash: event.hash,
      taskKey: 'TASK_KEY',
      inputs: mesg.encodeData({ key: 'INPUT_DATA' }),
      tags: ['ASSOCIATE_TAG'] // optional
    })
    if (result.error) {
      console.error('an error has occurred:', result.error)
      throw new Error(result.error)
    }
    console.log('a result received:', mesg.decodeData(result.outputs))

    Keywords

    none

    Install

    npm i @mesg/application

    DownloadsWeekly Downloads

    9

    Version

    0.2.1

    License

    ISC

    Unpacked Size

    26.9 kB

    Total Files

    8

    Last publish

    Collaborators

    • nicolasmahe
    • anthony-mesg
    • nicolas-mesg