LOKE IPC (Inter-process comms) Library
UPDATE: breaking change! constructor parameters are now different. Accepts an options argument. Can also be provided with a NewRelic client agent so that requests can be tracked and analyzed by NewRelic.
Connecting
var lokeIpc = ; lokeIpc;
Alternatively use the constructor:
var Communications = Communications; var communications = config;communicationsstart;
Specify the location of RabbitMQ:
var lokeIpc = ; lokeIpc;
Using NewRelic:
var lokeIpc = ;var newRelic = ; // if a new relic client is provided it will be usedlokeIpc;
Using a custom logger:
var lokeIpc = ;var logger = ; // a custom logger must implement .info .debug .warn .errorlokeIpc;
Consuming Services
var lokeIpc = ; lokeIpc;
Or use installed service manifests (see ipc-install):
$ ipc-install some-service@1
then
var lokeIpc = ; lokeIpc;
Publishing Services
TODO: see the following methods:
exposeService exposeServices closeServices
RPC Events
When exposing RPC methods a number of events are fired from RPC service and proxied through to communications to assist with logging and debugging.
// events for any/all exposed services are emitted on the connectionconnection;connection;connection; // events for a specific exposed service are emitted on the RPC service itselfrpcSvc;rpcSvc;rpcSvc;
For the following events a request object is of type:
id: 1 // message ID method: 'myMethodName' // method name params: // array[*] of params passed to the method
The response object is of type:
result: myResult // response from the method (type: any) error: null // JSON-RPC error will be null if there is a result id: id // the message ID from the request
In the event of an error:
result: null // null result in case of error error: code: -32000 // JSON-RPC error code message: "Failed abysmally" // error description data: {} // additional details (inner error or exception) id: id
request:start
conn;
request:complete
conn;
request:error
conn;
More
A custom logger can be provided. If none is provided then console will be used.
var lokeIpc = ; lokeIpc;
CLI
The cli tools are configured using rc. This means config variables can be set in
~/.ipcrc
./.ipcrc
(current directory, probably you project directory)
or by using a command line flag
--ipc_amqpuri='amqp://somehost'
The currently available variables are:
amqpuri
the amqp server to connect to
ipc-install
Usage: ipc-install <service>...
<service> in the format serviceName@version
example
$ ipc-install orders@1
writing... /my/project/ipc_manifests/orders.json
ipc-repl
Usage: ipc-repl
example
$ ipc-repl
ipc> orders.ping()
'pong'
ipc>