feat(batch25): implement gateway interest and outbound send logic
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user