How to authenticate rabbitmq in nodejs?

房东的猫 提交于 2019-12-12 18:01:26

问题


Error: Handshake terminated by server: 403 (ACCESS-REFUSED) with message "ACCESS_REFUSED - Login was refused using authen tication mechanism PLAIN. For details see the broker logfile." I tried authMechanism individually ('PLAIN', 'AMQPLAIN', 'EXTERNAL') but i'm getting same error. Unable to create connection with rabbitMQ

var raabitmqSettings = {
    protocol: 'amqp',
    hostname: '10.250.18.31',
    port: 5672,
    username: 'sam',
    password: 'sam@123',     
    vhost: '/',
    authMechanism: ['PLAIN', 'AMQPLAIN', 'EXTERNAL']
}

amqp.connect(raabitmqSettings, function(err, conn) {
    conn.createChannel(function(err, ch) {
         console.log("\n\n" + ch);
    }   
}

Where can i see log file in rabbit mq or how enable logs in rabbitMQ?

Is it right way to create connection? Is there any setting in rabbitMQ server?


回答1:


Use following code at receiver end

const open = await amqp.connect(setting);        
    var ch = await open.createChannel();
    await ch.assertExchange("cronService", "direct");
    var q = 'CronQueue';
    ch.assertQueue(q, { durable: true });
    ch.consume(q, async function(msg) {            
        console.log(" [x] Received %s", msg.content.toString());            
    }, { noAck: true });
    return something;


来源:https://stackoverflow.com/questions/51278469/how-to-authenticate-rabbitmq-in-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!