|
@@ -4,6 +4,7 @@ import (
|
|
|
"context"
|
|
|
"database/sql"
|
|
|
"encoding/json"
|
|
|
+ "fmt"
|
|
|
"regexp"
|
|
|
"time"
|
|
|
|
|
@@ -74,9 +75,10 @@ func (c *Client) withRequestIdContext(ctx context.Context, requestId string) con
|
|
|
// reader 读取到客户端发送的消息, 将消息发送到 nats 里
|
|
|
func (c *Client) reader() {
|
|
|
defer func() {
|
|
|
- c.srv.Disconnect <- c
|
|
|
- c.nats.Unsubscribe <- &subscriber{client: c}
|
|
|
- _ = c.UnderlyingConn.Close()
|
|
|
+ // c.srv.Disconnect <- c
|
|
|
+ // c.nats.Unsubscribe <- &subscriber{client: c}
|
|
|
+ // _ = c.UnderlyingConn.Close()
|
|
|
+ c.close()
|
|
|
}()
|
|
|
|
|
|
// 首次消息超时设置
|
|
@@ -104,7 +106,6 @@ func (c *Client) reader() {
|
|
|
zap.L().Error("[conn] read message error",
|
|
|
zap.String("user_id", c.UserId),
|
|
|
zap.Error(err))
|
|
|
- // c.close()
|
|
|
return
|
|
|
}
|
|
|
|
|
@@ -233,6 +234,7 @@ func (c *Client) reader() {
|
|
|
NotifyId: notification.Content.ID,
|
|
|
Sender: notification.Content.Sender,
|
|
|
Receiver: notification.Content.Receiver,
|
|
|
+ IsSent: models.NotifyNotReceived,
|
|
|
Payload: serializePayload(0, notification.Content.Payload),
|
|
|
}); err != nil {
|
|
|
c.ReplySend <- newErrorMessage(message.RequestId(), err)
|
|
@@ -242,6 +244,19 @@ func (c *Client) reader() {
|
|
|
c.Received <- message
|
|
|
}
|
|
|
|
|
|
+ case MessageTypeAck:
|
|
|
+
|
|
|
+ // 收到消息的回执, 处理回执消息
|
|
|
+ if notification, ok := message.(*Notification); ok {
|
|
|
+ notify, err := c.repos.NotifyRepository.Find(c.ctx, int64(notification.Content.AckId))
|
|
|
+ if err != nil || notify == nil {
|
|
|
+ c.ReplySend <- newErrorMessage(message.RequestId(), eris.New(fmt.Sprintf("unable to find notify ackId:%d", notification.Content.AckId)))
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ notify.IsSent = models.NotifyReceived
|
|
|
+ _ = c.repos.NotifyRepository.Save(c.ctx, notify)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|