|
@@ -10,6 +10,7 @@ class RabbitmqService extends Service {
|
|
|
this.durable = true;
|
|
|
// 定时任务队列
|
|
|
this.task = this.app.config.taskMqConfig;
|
|
|
+ this.httpUtil = this.ctx.service.util.httpUtil;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -17,20 +18,28 @@ class RabbitmqService extends Service {
|
|
|
* @param shop_id 店铺id
|
|
|
*/
|
|
|
async shopMsg(shop_id) {
|
|
|
- const { mq } = this.ctx;
|
|
|
- const ex = 'shopMsg';
|
|
|
+ // const { mq } = this.ctx;
|
|
|
+ // const ex = _.get(this, 'app.config.msgEx');
|
|
|
try {
|
|
|
- const ch = await mq.conn.createChannel();
|
|
|
- await ch.assertExchange(ex, 'direct', { durable: true });
|
|
|
- await ch.publish(ex, shop_id, Buffer.from('check msg'));
|
|
|
- await ch.close();
|
|
|
+ // 不用mq发消息,用http到聊天那边使用websocket发消息
|
|
|
+ const prefix = _.get(this.app, 'config.httpPrefix.chat');
|
|
|
+ const uri = '/sendWebSocket';
|
|
|
+ await this.httpUtil.cpost(`${prefix}${uri}`, { recevier: shop_id, type: 'shopMsg' });
|
|
|
+
|
|
|
+ // const ch = await mq.conn.createChannel();
|
|
|
+ // await ch.assertExchange(ex, 'direct', { durable: true });
|
|
|
+ // console.log(ex, shop_id);
|
|
|
+ // await ch.assertQueue(shop_id, { durable: false, exclusive: false });
|
|
|
+ // await ch.bindQueue(shop_id, ex);
|
|
|
+ // await ch.publish(ex, shop_id, Buffer.from(JSON.stringify({ type: 'shopMsg' })));
|
|
|
+ // // await ch.sendToQueue(shop_id, Buffer.from(JSON.stringify({ type: 'shopMsg' })));
|
|
|
+ // await ch.close();
|
|
|
} catch (error) {
|
|
|
console.error('mq--店铺系统消息--任务队列生成失败');
|
|
|
console.error(error);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// 初始化死信机制
|
|
|
async initDeadProcess() {
|
|
|
try {
|
|
@@ -41,7 +50,6 @@ class RabbitmqService extends Service {
|
|
|
return;
|
|
|
}
|
|
|
console.log('初始化:死信机制----成功');
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -54,7 +62,12 @@ class RabbitmqService extends Service {
|
|
|
// 声明正常交换器
|
|
|
await ch.assertExchange(this.task.ex, 'direct', { durable: true });
|
|
|
// 声明正常队列(配置死信队列设置)
|
|
|
- const q = await ch.assertQueue(this.task.queue, { durable: true, exclusive: false, deadLetterExchange: this.task.deadEx, deadLetterRoutingKey: this.task.deadLetterRoutingKey });
|
|
|
+ const q = await ch.assertQueue(this.task.queue, {
|
|
|
+ durable: true,
|
|
|
+ exclusive: false,
|
|
|
+ deadLetterExchange: this.task.deadEx,
|
|
|
+ deadLetterRoutingKey: this.task.deadLetterRoutingKey,
|
|
|
+ });
|
|
|
// 正常队里绑定至正常交换器
|
|
|
await ch.bindQueue(q.queue, this.task.ex);
|
|
|
} catch (error) {
|
|
@@ -104,7 +117,6 @@ class RabbitmqService extends Service {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 发送定时消息
|
|
|
* @param {String} queue 队列名
|