Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jeffutter opened this issue Feb 20, 2015 · 1 comment
Open

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

jeffutter opened this issue Feb 20, 2015 · 1 comment
Assignees

Comments

@jeffutter
Copy link

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 squaremo self-assigned this Feb 20, 2015
@squaremo
Copy link
Owner

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants