postwait / node-amqp

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

Cannot send message with very large header #398

Open tcabanski opened 9 years ago

tcabanski commented 9 years ago

I have a case where there is a very long message header I have to send. This causes either a connection error (if it is the only header) or an index out of range error (if it is one of many headers). I have .NET and Java clients that work fine with this header so it is not a limitation of RabbitMQ. This seems to happen when headers exceed 8126 bytes or so. Is there some setting that will let me get past this? Sample code:


String.prototype.repeat = function( num )
{
    return new Array( num + 1 ).join( this );
}
var amqp = require('amqplib');
var when = require('when');
var sizeof = require('object-sizeof');

function send(size) {
    return amqp.connect('amqp://test:test@services.local.com?frameMax=0').then(function (conn) {
        conn.on('error', function (err) {
            console.log('Connection error ' + err);
            conn.close();
        });
        return when(conn.createChannel().then(function (ch) {
            ch.on('error', function (err) {
                console.log('Channel error ' + err);
            });

            var options = {
                persistent: true,
                headers: {
                    "a": "x".repeat(size),
                    b: 'b',
                    c: 'c',
                    d: 'd',
                    e: 'e'
                }
            };

            return when.all([
                ch.assertQueue('foo'),
                ch.assertExchange('foo')
            ]).then(function(){
                ch.bindQueue('foo', 'foo');
            }).then(function(){
                ch.publish('foo', '', new Buffer('header with ' + size), options);
            }).then(function () {
                console.log('sent ' + sizeof(options.headers));
            }).catch(function (err) {
                console.log('error on send at size ' + sizeof(options.headers) + ' error: ' + err + ' ' + err.stack);
            });
        })).catch(function () {
            console.log('closing connection');
            conn.close();
        });
    });
}

//works
send(4054).then(function(){
    //fails
    send(4055);
});