Ver Fonte

增加mq配置

liuyu há 5 anos atrás
pai
commit
07f03c172f
4 ficheiros alterados com 49 adições e 19 exclusões
  1. 17 1
      app/service/user.js
  2. 22 10
      config/config.default.js
  3. 8 8
      config/plugin.js
  4. 2 0
      package.json

+ 17 - 1
app/service/user.js

@@ -110,7 +110,23 @@ class UserService extends CrudService {
       throw new BusinessError(ErrorCode.USER_NOT_EXIST);
     }
     user.openid = openid;
-    user.save();
+    const res = await user.save();
+    if (res) {
+      const { mq } = this.ctx;
+      if (mq) {
+        const msg = user.name + '绑定微信成功';
+        const parm = {
+          durable: true,
+          headers: {
+            userid: uid,
+          } };
+        console.log(parm);
+        console.log(msg);
+        await mq.topic('user_bind', uid, msg, parm);
+      } else {
+        this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
+      }
+    }
     return user;
   }
 

+ 22 - 10
config/config.default.js

@@ -58,16 +58,28 @@ module.exports = appInfo => {
   // 邮箱配置
   config.user_email = '1345526645@qq.com';
   config.auth_code = 'vnrzrxwserhyfeda';
-  // config.amqp = {
-  //   client: {
-  //     hostname: '127.0.0.1',
-  //     username: 'visit',
-  //     password: 'visit123',
-  //     vhost: 'visit',
-  //   },
-  //   app: true,
-  //   agent: true,
-  // };
+
+  // mq配置
+  config.amqp = {
+    client: {
+      hostname: '127.0.0.1',
+      username: 'visit',
+      password: 'visit',
+      vhost: 'train',
+    },
+    app: true,
+    agent: true,
+  };
+
+  // redis config
+  config.redis = {
+    client: {
+      port: 6379, // Redis port
+      host: '127.0.0.1', // Redis host
+      password: null,
+      db: 0,
+    },
+  };
 
   // mongoose config
   config.mongoose = {

+ 8 - 8
config/plugin.js

@@ -4,15 +4,15 @@ exports.multiTenancy = {
   enable: false,
 };
 
-// exports.amqp = {
-//   enable: true,
-//   package: 'egg-naf-amqp',
-// };
+exports.amqp = {
+  enable: true,
+  package: 'egg-naf-amqp',
+};
 
-// exports.redis = {
-//   enable: true,
-//   package: 'egg-redis',
-// };
+exports.redis = {
+  enable: true,
+  package: 'egg-redis',
+};
 
 // exports.nunjucks = {
 //   enable: true,

+ 2 - 0
package.json

@@ -13,6 +13,8 @@
     "jsonwebtoken": "^8.5.1",
     "lodash": "^4.17.15",
     "naf-framework-mongoose": "^0.6.11",
+    "egg-naf-amqp": "0.0.13",
+    "egg-redis": "^2.4.0",
     "nodemailer": "^6.4.3",
     "silly-datetime": "^0.1.2",
     "string-random": "^0.1.3",