log4js-node/rabbitmq

how-to DEBUG mode investigate connection issues

kmacpher67 opened this issue · 6 comments

Migrating from native "amqplib": "^0.5.2" to log4js.
Getting error on the connection socket.
We have ssl enabled and process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

 ERR { Error: Socket closed abruptly during opening handshake
 ERR     at Socket.endWhileOpening (/app/node_modules/amqplib/lib/connection.js:260:17)
 ERR     at Socket.emit (events.js:203:15)
 ERR     at endReadableNT (_stream_readable.js:1129:12)
 ERR     at process._tickCallback (internal/process/next_tick.js:63:19)

the config.rabbit is:

var rabbit = {
    type: '@log4js-node/rabbitmq',
    host: '127.0.0.1',
    port: 5672,
    username: 'guest',
    password: 'guest',
    routing_key: 's.system.log',
    exchange: 's.exchange.infrastructure.logger',
    mq_type: 'topic',
    con: {heartbeat: 30, protocol: 'amqps'}
  }````


Looks like the server is expecting a client certificate, but you're not supplying one. Which makes sense, because the appender doesn't know anything about SSL at the moment. It doesn't look like much work to add support for it going by the SSL Guide, (just pass a connection options object as the second argument to the connect call) but I don't have the expertise to work on this. Happy to see a PR that implements it though.

If you want to investigate this, then take a look at the integration.sh script in the test directory. It starts up a docker container running rabbitmq, then tries to connect to it using the node code. You could replace the docker image with one configured to run the same as the server you're trying to connect to.

i created a fork for enabling:
const protocol = config.protocol || 'amqp';
https://github.com/kmacpher67/rabbitmq
I added other variables too whilst in there.
I did not add any tests.

#12
did some minor clean up let me know.

ahh, incase anybody was interested. It's pretty simple.
export DEBUG=log4js* # shows all debug statements for log4js
export DEBUG=log4js:rabbitmq* # shows only debug for rabbitmq appender

Gareth Jones nomiddlename:
So the tap tests are failing, because they are expecting results back from amqp open (parameters).
Instead to get SSL working, I had to reconfigure the URL instead:

const socketOptions = con;
    amqplib.connect(url, socketOptions).then((c)

IMHO if i'm changing test code then this is non-trivial change.
I've never done node tap component tests (The fake mocks are voodoo tome) not that I can't figure it out, but when I do, are we still going to get a MR completed?
Let me know before I invest any further time on getting this branch to merge.