lrf hace 2 años
padre
commit
63b4b603be
Se han modificado 4 ficheros con 29 adiciones y 10 borrados
  1. 22 10
      app/service/util/rabbitMq.js
  2. 1 0
      config/config.default.js
  3. 4 0
      config/config.local.js
  4. 2 0
      config/config.prod.js

+ 22 - 10
app/service/util/rabbitMq.js

@@ -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 队列名

+ 1 - 0
config/config.default.js

@@ -81,6 +81,7 @@ module.exports = appInfo => {
     deadQueue: 'deadTaskQueue',
     deadLetterRoutingKey: 'deadTr',
   };
+  config.msgEx = 't_m';
 
   // 路由设置
   config.routePrefix = '/point/v1/api';

+ 4 - 0
config/config.local.js

@@ -83,6 +83,9 @@ module.exports = appInfo => {
     deadLetterRoutingKey: 'deadTrDevLocal',
   };
 
+  config.msgEx = 't_m_dev_local';
+
+
   // 路由设置
   config.routePrefix = '/dev/point/v1/api';
   // 支付路由回调设置
@@ -97,6 +100,7 @@ module.exports = appInfo => {
     // email: 'http://broadcast.waityou24.cn/semail/api',
     email: 'http://127.0.0.1:14002/semail/api',
     sms: 'http://127.0.0.1:14003/sms/api',
+    chat: 'http://127.0.0.1:12214/dev/point/chat/v1/api',
   };
   config.emailConfig = {
     config: 'free',

+ 2 - 0
config/config.prod.js

@@ -82,6 +82,7 @@ module.exports = appInfo => {
     deadQueue: 'deadTaskQueueDev',
     deadLetterRoutingKey: 'deadTrDev',
   };
+  config.msgEx = 't_m_dev';
 
   // 路由设置
   config.routePrefix = '/dev/point/v1/api';
@@ -97,6 +98,7 @@ module.exports = appInfo => {
     // email: 'http://broadcast.waityou24.cn/semail/api',
     email: 'http://127.0.0.1:14002/semail/api',
     sms: 'http://127.0.0.1:14003/sms/api',
+    chat: 'http://127.0.0.1:12214/dev/point/chat/v1/api',
   };
   config.emailConfig = {
     config: 'free',