Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed testcases, and fixed boomerang lib, forgot to return transport …
…from createTransport factory
  • Loading branch information
Mattias Ernelli committed Aug 17, 2012
1 parent bdc5a02 commit dc64cdf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
5 changes: 4 additions & 1 deletion lib/boomerang.js
@@ -1,4 +1,5 @@
var webservice = require("./webservice");
var utils = require("./utils");

function createTransport(client, options, callback) {
var transport;
Expand All @@ -10,7 +11,7 @@ function createTransport(client, options, callback) {
if(typeof options === "function") {
callback = options;
}

function _init() {
id = client.getClientId();
replySubject = "/inbox/" + id;
Expand Down Expand Up @@ -69,6 +70,8 @@ function createTransport(client, options, callback) {
} else {
_init();
}

return transport;
}

// export boomerang as the transport factory
Expand Down
18 changes: 11 additions & 7 deletions utils/listen.js
Expand Up @@ -2,10 +2,11 @@ var faye = require("faye");
var boomerang = require("../lib/boomerang.js");

var fayeServer = "http://localhost/faye";
var subject;
var subject, msg;

var narg = 2;
var argv = process.argv;

while(narg < argv.length) {
console.log("arg[" + narg + "] = " + argv[narg] );

Expand All @@ -17,24 +18,27 @@ while(narg < argv.length) {

if(!subject) {
subject = argv[narg];
}
} else if(!msg) {
msg = argv[narg];
}
}
narg++;
}

if(!subject) {
console.log("usage: listen [-faye server] subject");
console.log("usage: listen [-faye server] subject [msg]");
process.exit(1);
}


var client = new faye.Client(fayeServer);
var request = new boomerang(client, false, function() {
console.log("request/reply wrapper ready:");
console.log("inboxSubject: " + request.getInboxSubject());
var request = new boomerang.Transport(client, function() {
console.log("request is: ", request);

console.log("request/reply wrapper ready, listen to: " + subject);

request.listen(subject, function(msg, inmsg) {
console.log("got message on /marvin/test: ", msg);
console.log("got message on " + subject + ": ", msg);
request.sendReply( msg, inmsg);
console.log("reply sent");
});
Expand Down
25 changes: 8 additions & 17 deletions utils/send.js
Expand Up @@ -2,7 +2,7 @@ var faye = require("faye");
var boomerang = require("../lib/boomerang.js");

var fayeServer = "http://localhost/faye";
var subject, data;
var subject, msg;

var narg = 2;
var argv = process.argv;
Expand All @@ -17,14 +17,14 @@ while(narg < argv.length) {

if(!subject) {
subject = argv[narg];
} else if(!data) {
data = argv[narg];
} else if(!msg) {
msg = argv[narg];
}
}
narg++;
}

if(!subject || !data) {
if(!subject || !msg) {
console.log("usage: send [-faye server] subject data");
process.exit(1);
}
Expand All @@ -34,23 +34,14 @@ var client = new faye.Client(fayeServer);
var request = new boomerang(client, false, function() {
console.log("request/reply wrapper ready:");
console.log("inboxSubject: " + request.getInboxSubject());

console.log("send request to: " + subject);
console.log("message: " + msg);

request.sendRequest(subject, { data: data }, function(msg) {
request.sendRequest(subject, JSON.parse(msg), function(msg) {
console.log("got reply: ", msg);
process.exit();
});
console.log("request send, wait for reply");
});


/*
console.log("send message to /marvin, text: " + process.argv[2]);
var pub = client.publish('/marvin', { text: process.argv[2] } );
pub.callback(function () {
console.log("message sent!");
console.log("clientId: " + client.getClientId());
// process.exit();
});
*/

0 comments on commit dc64cdf

Please sign in to comment.