const amqp = require('amqplib')
module.exports = app => {
app.addSingleton('rabbitmq', createRabbitMQConnection);
}
async function createRabbitMQConnection(config, app) {
assert(config.hostname && config.port && config.username && config.password)
app.coreLogger.info('[egg-rabbitmqHelper] connecting %s"//%s:***@%s:%s',
config.protocol, config.username, config.hostname, config.port)
const conn = await amqp.connect({
// 配置
})
return conn
}
使用发现this.app.rabbitmq.createChannel is not a function 初始化方法不是支持Async吗
把config.default.js改成这样试一下:
module.exports=(appInfo)=>{
config.keys='123456';
config.rabbitmq= {
client: {
protocol: 'amqp',
hostname: 'my_rabbitmq_server',
port: 5672,
username: 'test',
password: 'test',
frameMax: 0,
heartbeat: 2, // 心跳
vhost: '/',
})
};
return config;
}
config.rabbitmq
rabbitmq 这个是app.addSingleton() 第一个参数的那个key的值。
@salamander-mh 有完整的demo吗?
Most helpful comment
把config.default.js改成这样试一下:
config.rabbitmq
rabbitmq 这个是app.addSingleton() 第一个参数的那个key的值。