|
@@ -29,13 +29,13 @@ export class MqSender {
|
|
|
* @param data 数据
|
|
|
*/
|
|
|
async toSendMsg(receiver, data) {
|
|
|
- await this.connect(receiver);
|
|
|
- const res = await this.sendMsg(receiver, data);
|
|
|
- console.log(res);
|
|
|
+ await this.connect(receiver, data);
|
|
|
+ // const res = await this.sendMsg(receiver, data);
|
|
|
+ // console.log(res);
|
|
|
await this.close();
|
|
|
}
|
|
|
|
|
|
- async connect(queue) {
|
|
|
+ async connect(queue, data) {
|
|
|
// 创建连接,你可以把配置放在 Config 中,然后注入进来
|
|
|
this.connection = await amqp.connect(this.mqUrl);
|
|
|
// 创建 channel
|
|
@@ -47,6 +47,7 @@ export class MqSender {
|
|
|
channel.assertExchange(_.get(this.mqConfig, 'ex'), 'direct', { durable: true }),
|
|
|
channel.assertQueue(queue, { durable: false, exclusive: false }),
|
|
|
channel.bindQueue(queue, _.get(this.mqConfig, 'ex')),
|
|
|
+ channel.publish(_.get(this.mqConfig, 'ex'), queue, { ...data, type: 'chat' })
|
|
|
]);
|
|
|
},
|
|
|
});
|