123456789101112131415161718192021222324252627282930 |
- 'use strict';
- const amqp = require('amqplib');
- const msgValue = require('../util/constants');
- const Controller = require('egg').Controller;
- class HomeController extends Controller {
- async index() {
- const { ctx } = this;
- ctx.body = 'hi, egg';
- }
- async sendmq() {
- const { ctx, app } = this;
- console.log(msgValue.MsgValues.EXCHANGE_CROP_REG);
- await this.service.rabbitmq.sendQueueMsg(ctx.query.exchange,ctx.query.routekey, new Buffer(JSON.stringify(ctx.query.msg)));
- ctx.body = '发送成功';
- }
- async receivemq() {
- const { ctx, app } = this;
- await this.service.rabbitmq.receiveQueueMsg(ctx.query.exchange,ctx.query.routekey,(msg) =>
- {
- console.log(msg);
- });
- ctx.body = "接收成功";
- }
- }
- module.exports = HomeController;
|