@yoda/flora

The flora module provide protocol of cross process communication. exports 'Agent' constructor for generate Agent instance.

// create flora agent instance
var flora = require('@yoda/flora')
var agent = new flora.Agent('unix:/var/run/flora.sock#testAgent')

// subscribe msg
agent.subscribe('test msg1', (msg, type) => {
  console.log('recv msg', msg)
})

agent.declareMethod('test method1', (msg, reply) => {
  console.log('method call params', msg)
  reply.writeCode(0)
  reply.writeData([ 'hello', 'world' ])
  reply.end()
});

// connect to unix domain socket '/var/run/flora.sock'
agent.start()

// post msg
agent.post('test msg1', [ 1, 2, 'hello world', [ 'foo' ] ], flora.MSGTYPE_INSTANT)

// remote call
agent.call('test method1', [ 'foo' ], 'testAgent', 200).then((reply) => {
  console.log('remote call return', msg)
}, (err) => {
  console.log('remote call failed:', err)
})

// close agent
// close agent after 1 second, for wait agent receive 'test msg1'
setTimeout(() => {
  agent.close()
}, 1000)

Classes

Agent
Response
Reply

Members

(static) MSGTYPE_INSTANT :number

(static) MSGTYPE_PERSIST :number

(static) ERROR_INVALID_URI :number

(static) ERROR_INVALID_PARAM :number

(static) ERROR_NOT_CONNECTED :number

(static) ERROR_TIMEOUT :number

(static) ERROR_TARGET_NOT_EXISTS :number

Type Definitions

SubscribeMsgHandler()

Parameters:
Type Description
Array.<any>

msg content

number

type of msg

DeclareMethodHandler()

Parameters:
Type Description
Array.<any>

msg content

module:@yoda/flora~Reply

an object that provide methods to reply data to caller