perf: expand gateway capacity and prevent receipt replay
This commit is contained in:
@@ -18,6 +18,7 @@ const defaultDownstreamAckTimeout = 30 * time.Second
|
||||
|
||||
type downstreamAckTracker struct {
|
||||
deliveryID string
|
||||
claimID string
|
||||
connectionID string
|
||||
sequenceID uint32
|
||||
messageID uint64
|
||||
@@ -69,29 +70,29 @@ func downstreamAckKey(conn *cmpp.Conn, sequenceID uint32) string {
|
||||
return fmt.Sprintf("%p:%d", conn, sequenceID)
|
||||
}
|
||||
|
||||
func registerDownstreamAck(session *downstreamSession, deliveryID string, sequenceID uint32, messageID uint64, deadline time.Time) *downstreamAckTracker {
|
||||
func registerDownstreamAck(session *downstreamSession, deliveryID string, claimID string, sequenceID uint32, messageID uint64, deadline time.Time) *downstreamAckTracker {
|
||||
if session == nil || session.conn == nil || strings.TrimSpace(deliveryID) == "" {
|
||||
return nil
|
||||
}
|
||||
tracker := &downstreamAckTracker{
|
||||
deliveryID: deliveryID, connectionID: session.connectionID,
|
||||
deliveryID: deliveryID, claimID: claimID, connectionID: session.connectionID,
|
||||
sequenceID: sequenceID, messageID: messageID, session: session,
|
||||
}
|
||||
key := downstreamAckKey(session.conn, sequenceID)
|
||||
downstreamAckRegistry.Lock()
|
||||
downstreamAckRegistry.items[key] = tracker
|
||||
downstreamAckRegistry.Unlock()
|
||||
tracker.timer = time.AfterFunc(time.Until(deadline), func() {
|
||||
timedOut := takeDownstreamAck(session.conn, sequenceID)
|
||||
if timedOut == nil || timedOut.session == nil || timedOut.session.deliveryReport == nil {
|
||||
return
|
||||
}
|
||||
timedOut.session.deliveryReport(downstreamDeliveryLifecycleEvent{
|
||||
Kind: "failed", DeliveryID: timedOut.deliveryID, ConnectionID: timedOut.connectionID,
|
||||
Kind: "failed", DeliveryID: timedOut.deliveryID, ClaimID: timedOut.claimID, ConnectionID: timedOut.connectionID,
|
||||
SequenceID: timedOut.sequenceID, MessageID: timedOut.messageID, ObservedAt: time.Now().UTC(),
|
||||
FailureType: "ack_timeout", ErrorMessage: "CMPP_DELIVER_RESP timeout",
|
||||
})
|
||||
})
|
||||
downstreamAckRegistry.Unlock()
|
||||
return tracker
|
||||
}
|
||||
|
||||
@@ -149,7 +150,7 @@ func handleDownstreamAcknowledgement(conn *cmpp.Conn, sequenceID uint32, message
|
||||
}
|
||||
if tracker.session != nil && tracker.session.deliveryReport != nil {
|
||||
go tracker.session.deliveryReport(downstreamDeliveryLifecycleEvent{
|
||||
Kind: "acknowledged", DeliveryID: tracker.deliveryID, ConnectionID: tracker.connectionID,
|
||||
Kind: "acknowledged", DeliveryID: tracker.deliveryID, ClaimID: tracker.claimID, ConnectionID: tracker.connectionID,
|
||||
SequenceID: sequenceID, MessageID: messageID, Result: result, ObservedAt: time.Now().UTC(),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user