home.js 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. const Controller = require('egg').Controller;
  3. class HomeController extends Controller {
  4. async index() {
  5. const { ctx } = this;
  6. ctx.body = 'hi, egg';
  7. }
  8. async sendmq() {
  9. const { ctx } = this;
  10. // const msg = { userid: ctx.body.userid, name: ctx.body.name, createtime: ctx.body.createtime, type: ctx.body.type, content: ctx.body.content, remark: ctx.body.remark };
  11. const msg = { userid: '2', name: 'hh', createtime: '2019-10-25 10:10:10', type: '1', content: '您有一个待办事项', remark: '别忘了' };
  12. const ex = 'schedule';
  13. const routekey = '11';
  14. const parm = { durable: true, headers: { userId: '2', type: '1', name: '哈哈' } };
  15. await this.service.rabbitmq.sendQueueMsg(ex, routekey, 'hhhsss', parm);
  16. this.ctx.body = '发送成功';
  17. }
  18. async receivemq() {
  19. const { ctx } = this;
  20. await this.service.rabbitmq.receiveQueueMsg(ctx.query.ex, ctx.query.routekey, msg => {
  21. console.log(msg);
  22. });
  23. ctx.body = '接收成功';
  24. }
  25. }
  26. module.exports = HomeController;