msgflo
Version:
Polyglot FBP runtime based on message queues
59 lines (49 loc) • 1.47 kB
JavaScript
var EventEmitter, ForeignParticipant, library, msgflo_nodejs;
msgflo_nodejs = require('msgflo-nodejs');
EventEmitter = require('events').EventEmitter;
library = require('./library');
ForeignParticipant = class ForeignParticipant extends EventEmitter {
constructor(client, def) {
super();
if (typeof client === 'string') {
client = msgflo_nodejs.transport.getClient(client);
}
this.messaging = client;
this.definition = def;
}
register(callback) {
return this.messaging.registerParticipant(this.definition, function(err) {
return callback(err);
});
}
};
exports.ForeignParticipant = ForeignParticipant;
exports.register = function(client, definition, callback) {
var participant;
participant = new ForeignParticipant(client, definition);
return participant.register(callback);
};
exports.mapPorts = function(definition) {
var inPorts, outPorts;
inPorts = definition.inports || {};
definition.inports = Object.keys(inPorts).map(function(id) {
var def;
def = inPorts[id];
def.id = id;
def.queue = library.replaceVariables(def.queue, {
"ROLE": definition.role
});
return def;
});
outPorts = definition.outports || {};
definition.outports = Object.keys(outPorts).map(function(id) {
var def;
def = outPorts[id];
def.id = id;
def.queue = library.replaceVariables(def.queue, {
"ROLE": definition.role
});
return def;
});
return definition;
};