我正在尝试实现一个NodeJS
微服务,我需要它来使用RabbitMQ
. 对于 rabbit 集成,我使用的是 ' rascal ' ( https://github.com/guidesmiths/rascal ),因为它解决了我的很多问题。我注意到 rascal 是由一个配置文件驱动的,您可以在其中声明兔子 URL、用户名、密码等。
我的问题是,在流氓配置文件中保护这些密码的最佳做法是什么?
a) 不被推送到 git
b) 不那么容易暴露
我正在尝试实现一个NodeJS
微服务,我需要它来使用RabbitMQ
. 对于 rabbit 集成,我使用的是 ' rascal ' ( https://github.com/guidesmiths/rascal ),因为它解决了我的很多问题。我注意到 rascal 是由一个配置文件驱动的,您可以在其中声明兔子 URL、用户名、密码等。
我的问题是,在流氓配置文件中保护这些密码的最佳做法是什么?
a) 不被推送到 git
b) 不那么容易暴露
使用 amqplib npm 模块在 nodejs 上使用 rabbitmq 集成。我在 rabbitmq 上给出了示例发布消费代码。
发布代码:
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://username:password@localhost:5672', function(err, connection) {
if (err) throw err;
connection.createChannel(function(err, channel) {
if (err) throw err;
var exchange = 'data';
var msg = "Welcome to Node and rabbitMQ";
channel.assertExchange(exchange, 'fanout', {
durable: false
})
channel.publish(exchange, '', Buffer.from(msg));
console.log(msg)
})
})
消费代码
var amqp = require('amqplib/callback_api');
amqp.connect('amqp://username:password@localhost:5672', function(err0, connection) {
if (err0) throw err0;
connection.createChannel(function(err1, channel) {
if (err1) throw err1;
var exchange = 'data';
channel.assertExchange(exchange, 'fanout', { durable: false })
channel.assertQueue('', {
exclusive: true
}, function(err2, value) {
channel.bindQueue(value.queue, exchange, '');
channel.consume(value.queue, function(msg) {
console.log("message:", msg.content.toString())
}, { noAck: true })
})
})
})