1234567891011121314151617181920212223242526272829303132333435363738 |
- '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)), (data) =>
- {
- console.log(data);
-
- });
- ctx.body = '发送成功';
- }
- async receivemq() {
- const { ctx, app } = this;
- await this.service.rabbitmq.receiveQueueMsg(ctx.query.exchange,ctx.query.routekey,(msg) =>
- {
- console.log(msg);
-
- // 插入待办事项到数据库中。
- await this.service.message.create({producerid: '1', consumerid: '2',type: '1', content: '2222'});
- });
- ctx.body = "接收成功";
- }
- }
- module.exports = HomeController;
|