home.js 791 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. const amqp = require('amqplib');
  3. const msgValue = require('../util/constants');
  4. const Controller = require('egg').Controller;
  5. class HomeController extends Controller {
  6. async index() {
  7. const { ctx } = this;
  8. ctx.body = 'hi, egg';
  9. }
  10. async sendmq() {
  11. const { ctx, app } = this;
  12. console.log(msgValue.MsgValues.EXCHANGE_CROP_REG);
  13. await this.service.rabbitmq.sendQueueMsg(ctx.query.exchange,ctx.query.routekey, new Buffer(JSON.stringify(ctx.query.msg)));
  14. ctx.body = '发送成功';
  15. }
  16. async receivemq() {
  17. const { ctx, app } = this;
  18. await this.service.rabbitmq.receiveQueueMsg(ctx.query.exchange,ctx.query.routekey,(msg) =>
  19. {
  20. console.log(msg);
  21. });
  22. ctx.body = "接收成功";
  23. }
  24. }
  25. module.exports = HomeController;