squaremo / rabbit.js

Messaging in Node.JS made easy using RabbitMQ
Other
1.52k stars 142 forks source link

Buffer.write: Cannot read property 'length' of undefined #92

Open jeffutter opened 9 years ago

jeffutter commented 9 years ago

I am having an odd error here that I can't seem to track down. I am new to rabbitmq and rabbit.js so I am likely doing something wrong. I am trying to setup a REQ/REP and even this simple example is failing when I send a message.

Here is the code from my server:

"use strict";

var context = rabbit.createContext("amqp://" + process.env.RABBITMQ_USER + ":" + process.env.RABBITMQ_PASSWORD + "@" + process.env.RABBITMQ_1_PORT_5672_TCP_ADDR + ":" + process.env.RABBITMQ_1_PORT_5672_TCP_PORT);

context.on("ready", function () {
  console.log("Rabbit Listening");
  var rep = context.socket("REP");
  rep.setEncoding("utf8");

  rep.on("data", function (msg) {
    var data = JSON.parse(msg);
    console.log("Message Received %j", data);
    var jobId = data.job_id;
    var outData = { test: true };
    console.log("Replying with %j", outData);
    var res = JSON.stringify(outData);
    rep.write(res, "utf8");
  });
  rep.connect("pos.receipt.pdf");
});

context.on("error", function (e) {
  console.error(e, "Rabbit Error");
});

And here is the output I get:

Rabbit Listening
Message Received {"job_id":12711}
Replying with {"test":true}
events.js:125
      throw er; // Unhandled 'error' event
            ^
TypeError: Cannot read property 'length' of undefined
    at Buffer.write (buffer.js:400:13)
    at encodeBasicPublish (node_modules/rabbit.js/node_modules/amqplib/lib/defs.js:2167:10)
    at module.exports.encodeMethod (node_modules/rabbit.js/node_modules/amqplib/lib/defs.js:3527:12)
    at Connection.C.sendMessage (node_modules/rabbit.js/node_modules/amqplib/lib/connection.js:511:16)
    at Channel.C.sendMessage (node_modules/rabbit.js/node_modules/amqplib/lib/channel.js:79:26)
    at Channel.C.publish (node_modules/rabbit.js/node_modules/amqplib/lib/channel_model.js:343:15)
    at Channel.C.sendToQueue (node_modules/rabbit.js/node_modules/amqplib/lib/channel_model.js:347:15)
    at RepSocket.write (node_modules/rabbit.js/lib/sockets.js:490:16)
    at RepSocket.<anonymous> (src/javascript/node/rabbit.js:20:9)
    at emitOne (events.js:75:13

Any suggestions on how to debug this?

squaremo commented 9 years ago

That .. looks fine and works fine for me. Odd indeed.

What versions of Node.JS and rabbit.js are you using?