perf: expand gateway capacity and prevent receipt replay
This commit is contained in:
@@ -88,7 +88,16 @@ func (c *connection) handleDeliver(pkt deliverPacket) error {
|
||||
DeliveredAt: time.Now().UTC(),
|
||||
ConnectionID: c.identity(),
|
||||
}
|
||||
if err := postJSON(context.Background(), c.httpClient, c.apiBaseURL, "/gateway/events/receipt/intake", event); err != nil {
|
||||
if c.protocolLogPublisher != nil {
|
||||
c.emitProtocolLog(protocolLogEvent{Protocol: "cmpp", Direction: "channel_to_platform", EventType: "deliver_receipt", Status: "success", ChannelID: channelID, Account: c.config.Account, MessageID: messageID, GatewayMessageID: fmt.Sprint(receipt.MsgId), Phone: strings.TrimSpace(receipt.DestTerminalId), ResultCode: strings.TrimSpace(receipt.Stat), Detail: map[string]any{"sequenceId": pkt.seqID}})
|
||||
}
|
||||
var publishErr error
|
||||
if c.eventPublisher != nil {
|
||||
publishErr = c.eventPublisher.PublishReceipt(context.Background(), event)
|
||||
} else {
|
||||
publishErr = postJSON(context.Background(), c.httpClient, c.apiBaseURL, "/gateway/events/receipt/intake", event)
|
||||
}
|
||||
if err := publishErr; err != nil {
|
||||
log.Printf("protocol_event protocol=cmpp direction=gateway_to_api event=deliver_receipt status=forward_failed channel_id=%s sequence_id=%d gateway_message_id=%d error=%q", c.channelID, pkt.seqID, receipt.MsgId, err)
|
||||
return err
|
||||
} else {
|
||||
@@ -121,7 +130,16 @@ func (c *connection) handleDeliver(pkt deliverPacket) error {
|
||||
Content: content,
|
||||
ReceivedAt: time.Now().UTC(),
|
||||
}
|
||||
if err := postJSON(context.Background(), c.httpClient, c.apiBaseURL, "/gateway/events/uplink", event); err != nil {
|
||||
if c.protocolLogPublisher != nil {
|
||||
c.emitProtocolLog(protocolLogEvent{Protocol: "cmpp", Direction: "channel_to_platform", EventType: "deliver_uplink", Status: "success", ChannelID: c.channelID, Account: c.config.Account, MessageID: cmd.MessageID, Phone: strings.TrimSpace(pkt.srcTerminalID), Detail: map[string]any{"sequenceId": pkt.seqID}})
|
||||
}
|
||||
var publishErr error
|
||||
if c.eventPublisher != nil {
|
||||
publishErr = c.eventPublisher.PublishUplink(context.Background(), event)
|
||||
} else {
|
||||
publishErr = postJSON(context.Background(), c.httpClient, c.apiBaseURL, "/gateway/events/uplink", event)
|
||||
}
|
||||
if err := publishErr; err != nil {
|
||||
log.Printf("protocol_event protocol=cmpp direction=gateway_to_api event=deliver_uplink status=forward_failed channel_id=%s sequence_id=%d packet_msg_id=%d error=%q", c.channelID, pkt.seqID, pkt.msgID, err)
|
||||
} else {
|
||||
log.Printf("protocol_event protocol=cmpp direction=gateway_to_api event=deliver_uplink status=forwarded channel_id=%s sequence_id=%d packet_msg_id=%d", c.channelID, pkt.seqID, pkt.msgID)
|
||||
|
||||
Reference in New Issue
Block a user