|
@@ -3,6 +3,7 @@ import * as amqp from 'amqp-connection-manager';
|
|
|
import { Application } from '@midwayjs/koa';
|
|
|
import _ = require('lodash');
|
|
|
import * as computedUtil from '../../util/computed';
|
|
|
+import { retryWithAsync } from '@midwayjs/core';
|
|
|
@Autoload()
|
|
|
@Provide()
|
|
|
@Scope(ScopeEnum.Singleton)
|
|
@@ -12,7 +13,7 @@ export class MqSender {
|
|
|
|
|
|
private connection: amqp.AmqpConnectionManager;
|
|
|
|
|
|
- private channelWrapper;
|
|
|
+ private channelWrapper: amqp.ChannelWrapper;
|
|
|
|
|
|
@Config('rabbitmq.url')
|
|
|
mqUrl: object;
|
|
@@ -54,13 +55,23 @@ export class MqSender {
|
|
|
const min = this.timeout;
|
|
|
// 转换成毫秒
|
|
|
const ms = computedUtil.multiply(min, 60000);
|
|
|
- return this.channelWrapper.sendToQueue(q, { ...data, type: 'order' }, { expiration: ms });
|
|
|
+ // return this.channelWrapper.sendToQueue(q, { ...data, type: 'order' }, { expiration: ms });
|
|
|
+ const retryFunc = retryWithAsync(this.sendMessage, 2, { receiver: this, retryInterval: 3000 });
|
|
|
+ const r = await retryFunc(q, data, 'order', ms);
|
|
|
+ return r;
|
|
|
}
|
|
|
|
|
|
/**团死信消息 */
|
|
|
async groupMsg(data: object, ms: number) {
|
|
|
const q = _.get(this.mqConfig, 'q');
|
|
|
- return this.channelWrapper.sendToQueue(q, { ...data, type: 'group' }, { expiration: ms });
|
|
|
+ // const r = await this.sendMessage(q, data, 'group', ms);
|
|
|
+ const retryFunc = retryWithAsync(this.sendMessage, 2, { receiver: this, retryInterval: 3000 });
|
|
|
+ const r = await retryFunc(q, data, 'group', ms);
|
|
|
+ return r;
|
|
|
+ }
|
|
|
+
|
|
|
+ async sendMessage(q, data, type, ms) {
|
|
|
+ return await this.channelWrapper.sendToQueue(q, { ...data, type }, { expiration: ms });
|
|
|
}
|
|
|
|
|
|
@Destroy()
|