Skip to content

StreamMachine/ipc-rpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


ipc-rpc

RPC over process.send, including support for sending handles.

Both sides of the pipe can be both clients and servers.

Usage

Set up a basic server that responds to status requests with "OK!":

  functions =
    status: (msg,handle,cb) ->
      cb null, "OK!"

  rpc = new RPC process, functions:functions, timeout:500

On the client-side:

  rpc = new RPC server, (err) =>
    if err
      # probably didn't pass in something with `.send` as server
      throw err

    # ready

  rpc.request "status", msg:"whatever", (err,result) =>
    # err should be null and result should be "OK!"

Requests optionally take a handle as their third argument, before the callback.

Motivation

In StreamMachine, this library is used to facilitate handoffs of server and listener data during seamless restarts.

Example call (found here in StreamMachine):

  for source in sg._stream.sources
      if source._shouldHandoff
          do (source) =>
              @log.info "Sending StreamGroup source #{msg.key}/#{source.uuid}"
              rpc.request "group_source",
                  group:      sg.key
                  type:       source.HANDOFF_TYPE
                  opts:       format:source.opts.format, uuid:source.uuid, source_ip:source.opts.source_ip
              , source.opts.sock
              , (err,reply) =>
                  @log.error "Error sending group source #{msg.key}/#{source.uuid}: #{err}" if err
                  af()

About

RPC over Node.js process.send

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published