postwait / node-amqp

[UNMAINTAINED] node-amqp is an AMQP client for nodejs
MIT License
1.69k stars 357 forks source link

'Unknown field value' error when receiving AMQP messages sent from MQTT client #331

Closed pklicnik closed 9 years ago

pklicnik commented 10 years ago

I am trying to publish a message into an MQTT topic and receive it as an AMQP message using the node-amqp client.

To do this, I am using RabbitMQ for Windows (version 3.2.4) with MQTT plugin enabled (see http://www.rabbitmq.com/blog/2012/09/12/mqtt-adapter/). The MQTT plugin will publish into the "amq.topic" exchange, and I'm binding a queue to that exchange to start listening.

The node-amqp module appears to be receiving the message, but is unable to parse it. I added an error handler to the amqp connection, and I get the following error: [Error: Unknown field value type 98]

Which is being thrown by the parseValue() function in /amqp/lib/parser.js. Note that this setup works with other consumer clients (for node.js and Java), so I believe it's a bug with node-amqp.

Below are a sample produce and consumer which can be used to reproduce the problem Producer

var readline = require("readline"),
    url = require("url"),
    mqtt = require("mqtt");

var mqttUrl = url.parse("http://localhost:1883");
var mqClient = mqtt.createClient(mqttUrl.port, mqttUrl.hostname);
mqClient.publish("test-messages", JSON.stringify({"message": "hello world!"}));

Consumer

var amqp = require('amqp'),
    readline = require("readline"),
    util = require("util");

var connection = amqp.createConnection({host : 'localhost'}, {defaultExchangeName : "amq.topic"});
connection.on('ready', function() {
    connection.queue("my-queue", {durable : true}, function(q) {
        q.bind('#');
        q.subscribe(function(message, headers, deliveryInfo, messageObject) {
            console.log('Node AMQP: received topic "' + deliveryInfo.routingKey + '", message: "' + message.data.toString() + '"');
        });
    });
});
connection.on('error', function(err) {
    console.log(util.inspect(err, {depth: null}));
});

var rl = readline.createInterface({
    input : process.stdin,
    output : process.stdout
});
rl.question("Press enter to quit: \n", function() {
    console.log("Exiting...");
    process.exit(0);
});
dglozic commented 10 years ago

+1 It does not seem to matter which client you use to publish - I got the same result using Eclipse PAHO Java client to publish an MQTT message, and using RabbitMQ for the broker.

When using AMQP client to publish to "amq.topic" exchange, the error is absent - I get message print to the console as expected.

evertharmeling commented 9 years ago

Seems like I have the same problem, I'm using the PubSubClient on my Arduino and receiving this error. When publishing with PHP with the videlalvaro/php-amqplib it works as expecting (receiving the messages).

But I can receive the Arduino message with my PHP library.

In my case the parseValue function (in /amqp/lib/parser.js), switch(buffer[buffer.read++]) returns 70...