fix(lmxproxy): make MxAccess client name unique per instance
Multiple instances registering with the same name may cause MxAccess to conflict on callback routing. ClientName is now configurable via appsettings.json, defaulting to a GUID-suffixed name if not set. Instances A and B use "LmxProxy-A" and "LmxProxy-B" respectively. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,9 @@ namespace ZB.MOM.WW.LmxProxy.Host.Configuration
|
||||
/// <summary>Path to API key configuration file. Default: apikeys.json.</summary>
|
||||
public string ApiKeyConfigFile { get; set; } = "apikeys.json";
|
||||
|
||||
/// <summary>Unique client name for MxAccess Register(). Must be unique per instance. Default: auto-generated.</summary>
|
||||
public string? ClientName { get; set; }
|
||||
|
||||
/// <summary>MxAccess connection settings.</summary>
|
||||
public ConnectionConfiguration Connection { get; set; } = new ConnectionConfiguration();
|
||||
|
||||
|
||||
@@ -70,7 +70,8 @@ namespace ZB.MOM.WW.LmxProxy.Host
|
||||
probeTestTagAddress: _config.HealthCheck.TestTagAddress,
|
||||
probeTimeoutMs: _config.HealthCheck.ProbeTimeoutMs,
|
||||
maxConsecutiveTransportFailures: _config.HealthCheck.MaxConsecutiveTransportFailures,
|
||||
degradedProbeIntervalMs: _config.HealthCheck.DegradedProbeIntervalMs);
|
||||
degradedProbeIntervalMs: _config.HealthCheck.DegradedProbeIntervalMs,
|
||||
clientName: _config.ClientName);
|
||||
|
||||
// 5. Connect to MxAccess synchronously (with timeout)
|
||||
Log.Information("Connecting to MxAccess (timeout: {Timeout}s)...",
|
||||
|
||||
@@ -107,8 +107,9 @@ namespace ZB.MOM.WW.LmxProxy.Host.MxAccess
|
||||
_lmxProxy.OnDataChange += OnDataChange;
|
||||
_lmxProxy.OnWriteComplete += OnWriteComplete;
|
||||
|
||||
// Register with MxAccess
|
||||
_connectionHandle = _lmxProxy.Register("ZB.MOM.WW.LmxProxy.Host");
|
||||
// Register with MxAccess using unique client name
|
||||
_connectionHandle = _lmxProxy.Register(_clientName);
|
||||
Log.Information("Registered with MxAccess as '{ClientName}'", _clientName);
|
||||
|
||||
if (_connectionHandle <= 0)
|
||||
{
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace ZB.MOM.WW.LmxProxy.Host.MxAccess
|
||||
private readonly bool _autoReconnect;
|
||||
private readonly string? _nodeName;
|
||||
private readonly string? _galaxyName;
|
||||
private readonly string _clientName;
|
||||
|
||||
private readonly SemaphoreSlim _readSemaphore;
|
||||
private readonly SemaphoreSlim _writeSemaphore;
|
||||
@@ -81,7 +82,8 @@ namespace ZB.MOM.WW.LmxProxy.Host.MxAccess
|
||||
string? probeTestTagAddress = null,
|
||||
int probeTimeoutMs = 5000,
|
||||
int maxConsecutiveTransportFailures = 3,
|
||||
int degradedProbeIntervalMs = 30000)
|
||||
int degradedProbeIntervalMs = 30000,
|
||||
string? clientName = null)
|
||||
{
|
||||
_maxConcurrentOperations = maxConcurrentOperations;
|
||||
_readTimeoutMs = readTimeoutSeconds * 1000;
|
||||
@@ -94,6 +96,7 @@ namespace ZB.MOM.WW.LmxProxy.Host.MxAccess
|
||||
_probeTimeoutMs = probeTimeoutMs;
|
||||
_maxConsecutiveTransportFailures = maxConsecutiveTransportFailures;
|
||||
_degradedProbeIntervalMs = degradedProbeIntervalMs;
|
||||
_clientName = clientName ?? "LmxProxy-" + Guid.NewGuid().ToString("N").Substring(0, 8);
|
||||
|
||||
_readSemaphore = new SemaphoreSlim(maxConcurrentOperations, maxConcurrentOperations);
|
||||
_writeSemaphore = new SemaphoreSlim(maxConcurrentOperations, maxConcurrentOperations);
|
||||
|
||||
Reference in New Issue
Block a user