|
@@ -11,6 +11,27 @@ class Person_chatService extends CrudService {
|
|
|
super(ctx, 'person_chat');
|
|
|
this.model = this.ctx.model.PersonChat;
|
|
|
}
|
|
|
+ async create(data) {
|
|
|
+ const res = await this.model.create(data);
|
|
|
+ if (res) {
|
|
|
+ const exchange = 'personChat';
|
|
|
+ // const routeKey = `${res.room_id}/${res.receiver_id}`;
|
|
|
+ const routeKey = 'test';
|
|
|
+ const content = JSON.stringify(_.pick(res, [ 'sender_id', 'sender_name', 'receiver_id', 'receiver_name', 'room_id', 'content', 'is_read', 'send_time' ]));
|
|
|
+ const param = { durable: true };
|
|
|
+ const { mq } = this.ctx;
|
|
|
+ if (mq) {
|
|
|
+ try {
|
|
|
+ await mq.topic(exchange, routeKey, content, param);
|
|
|
+ } catch (error) {
|
|
|
+ this.ctx.logger.error(error);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.ctx.logger.error('!!!!!!没有配置MQ插件!!!!!!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = Person_chatService;
|