1 | # msgflo-nodejs [![Build Status](https://travis-ci.org/msgflo/msgflo-nodejs.svg?branch=master)](https://travis-ci.org/msgflo/msgflo-nodejs)
|
2 |
|
3 | [MsgFlo](https://github.com/msgflo/msgflo) is a distributed, polyglot FBP (flow-based-programming)
|
4 | runtime. It integrates with other FBP tools like the [Flowhub](http://flowhub.io) visual programming IDE.
|
5 |
|
6 | This library makes it easy to create MsgFlo participants in JavaScript/CoffeScript on node.js.
|
7 |
|
8 | ## Status
|
9 |
|
10 | **Production**
|
11 |
|
12 | * Used at [TheGrid](https://thegrid.io) for all workers using AMQP/RabbitMQ,
|
13 | including in [imgflo-server](https://github.com/jonnor/imgflo-server)
|
14 | * Also used by [noflo-runtime-msgflo](https://github.com/noflo/noflo-runtime-msgflo)
|
15 | * Experimental support for MQTT and direct transports
|
16 |
|
17 | ## Licence
|
18 |
|
19 | MIT, see [./LICENSE](./LICENSE)
|
20 |
|
21 | ## Usage
|
22 |
|
23 | Add as an NPM dependency
|
24 |
|
25 | npm install --save msgflo-nodejs
|
26 |
|
27 | A simple participant (CoffeeScript)
|
28 |
|
29 | msgflo = require 'msgflo-nodejs'
|
30 |
|
31 | RepeatParticipant = (client, role) ->
|
32 | definition =
|
33 | component: 'Repeat'
|
34 | icon: 'file-word-o'
|
35 | label: 'Repeats in data without changes'
|
36 | inports: [
|
37 | id: 'in'
|
38 | type: 'any'
|
39 | ]
|
40 | outports: [
|
41 | id: 'out'
|
42 | type: 'any'
|
43 | ]
|
44 | process = (inport, indata, callback) ->
|
45 | return callback 'out', null, indata
|
46 | return new msgflo.participant.Participant client, definition, process, role
|
47 |
|
48 | client = msgflo.transport.getClient 'amqp://localhost'
|
49 | worker = RepeatParticipant client, 'repeater'
|
50 | worker.start (err) ->
|
51 | throw err if err
|
52 | console.log 'Worker started'
|
53 |
|
54 | If you expose the participant factory function ([examples/Repeat.coffee](./examples/Repeat.coffee))
|
55 |
|
56 | module.exports = RepeatParticipant
|
57 |
|
58 | Then you can use the `msgflo-nodejs` exectutable to start participant
|
59 |
|
60 | msgflo-nodejs --name repeater ./examples/Repeat.coffee
|
61 |
|
62 | ## Debugging
|
63 |
|
64 | msgflo-nodejs uses the [debug NPM module](https://www.npmjs.com/package/debug).
|
65 | You can enable (all) logging using:
|
66 |
|
67 | export DEBUG=msgflo*
|
68 |
|
69 | ## Supporting other transports
|
70 |
|
71 | msgflo-nodejs has a transport abstraction layer. So to support a new messaging system,
|
72 | implement `Client` and `MessageBroker` [interfaces](./src/interfaces.coffee).
|
73 |
|
74 | You can then pass the Client instance into a `Participant`.
|
75 |
|
76 | Or you can register a new transport using `msgflo.transport.register('mytransport', myTransportModule)`.
|
77 | Then you can get a Client instance using `msgflo.transport.getClient('mytransport://somehost:666')`.
|
78 | This has the advantage of also working when specifying the broker URL using
|
79 | `msgflo-nodejs --broker` or `MSGFLO_BROKER=` environment variable.
|
80 |
|