feat(batch25): implement gateway interest and outbound send logic

This commit is contained in:
Joseph Doherty
2026-03-01 02:00:08 -05:00
parent 0fece7f2f3
commit 59fa600b3c
6 changed files with 271 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
// Copyright 2018-2026 The NATS Authors
// Licensed under the Apache License, Version 2.0
using System.Text;
namespace ZB.MOM.NatsNet.Server;
public sealed partial class ClientConnection
{
internal void SendMsgToGateways(Account? account, byte[] subject, byte[]? reply, byte[] payload)
{
if (Server is not NatsServer server || account == null || subject.Length == 0)
return;
var outboundGateways = server.GetOutboundGatewayConnections();
if (outboundGateways.Count == 0)
return;
foreach (var gateway in outboundGateways)
{
if (!GatewayInterest(account, Encoding.ASCII.GetString(subject)))
continue;
var replyToSend = reply;
if (reply is { Length: > 0 } && gateway.Gateway != null)
{
var shouldMap = server.ShouldMapReplyForGatewaySend(reply, gateway.Gateway.UseOldPrefix);
if (shouldMap)
replyToSend = reply;
}
var proto = MsgHeader(subject, replyToSend, new Internal.Subscription { Sid = Encoding.ASCII.GetBytes("1") });
gateway.EnqueueProto(proto);
gateway.EnqueueProto(payload);
gateway.EnqueueProto(Encoding.ASCII.GetBytes("\r\n"));
}
}
}