seneca-transport

Seneca transport

npm install seneca-transport
17 downloads in the last day
53 downloads in the last week
255 downloads in the last month

seneca-transport

An action transport plugin for the Seneca framework

This plugin allows you to execute Seneca actions in separate Seneca processes. The default transport mechanism is HTTP. Redis publish-subscribe is also built-in.

This plugin provides the implementation for the listen, client, and proxy convenience methods on the Seneca object. It is included as a dependent module of the Seneca module.

You can provide your own transport mechanisms by overriding the transport action patterns (see below).

Support

If you're using this module, feel free to contact me on Twitter if you have any questions! :) @rjrodger

Current Version: 0.1.2

Tested on: Node 0.10.24, Seneca 0.5.17

Build Status

Quick example

First, define a service (this is just a Seneca plugin):

module.exports = function() {
  this.add( 'foo:1', function(args,done){done(null,{s:'1-'+args.bar})} )
  this.add( 'foo:2', function(args,done){done(null,{s:'2-'+args.bar})} )
}

Start the service:

require('seneca')()
  .use('foo')
  .listen()

And talk to it:

require('seneca')()
  .listen()
  .ready(function(){
    this.act('foo:1,bar:A',function(err,out){console.log(out)})
    this.act('foo:2,bar:B',function(err,out){console.log(out)})
  })

And this prints:

1-A
2-B

To run this example, try in one terminal

node test/service-foo.js

and in another:

node test/client-foo.js

Install

This module is included in the standard Seneca module, so install using that:

npm install seneca

Action Patterns

role:transport, cmd:listen

Starts listening for actions. The type argument specifies the transport mechanism. Current built-ins are direct (which is HTTP), and pubsub (which is Redis).

role:transport, cmd:client

Create a Seneca instance that sends actions to a remote service. The type argument specifies the transport mechanism.

Hook Patterns

These patterns are called by the primary action patterns. Add your own for additional transport mechanisms.

  • role:transport, hook:listen, type:direct
  • role:transport, hook:client, type:pubsub
  • role:transport, hook:listen, type:direct
  • role:transport, hook:client, type:pubsub

These all take additional configuration arguments, which are passed through from the primary actions:

  • host
  • port
  • path (not used by pubsub)

Pattern Selection

If you only want to transport certain action patterns, use the pin argument to pick these out. See the test/client-pubsub-foo.js and test/service-pubsub-foo.js files for an example.

Logging

To see what this plugin is doing, try:

node your-app.js --seneca.log=plugin:transport

To skip the action logs, use:

node your-app.js --seneca.log=type:plugin,plugin:transport

For more on logging, see the seneca logging example.

Test

cd test
mocha transport.test.js --seneca.log.all
npm loves you