Skip to content

Commit 6a4de38

Browse files
committed
updated logic to use durable buffer path if provided
1 parent 67d2be0 commit 6a4de38

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

  • agent/Modules/MTConnect.NET-AgentModule-MqttRelay

agent/Modules/MTConnect.NET-AgentModule-MqttRelay/Module.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public class Module : MTConnectAgentModule
3838
private static readonly object _lastSentSequenceLock = new object();
3939
private long _totalIncomingObservations = 0;
4040
private long _lastSentSequence = 0;
41-
41+
private const string DirectoryBuffer = "buffer";
42+
private const string LastSentSequenceFileName = "mqttrelay_last_sent.seq";
4243

4344
public Module(IMTConnectAgentBroker mtconnectAgent, object configuration) : base(mtconnectAgent)
4445
{
@@ -334,17 +335,24 @@ private async Task RelayBufferedObservations()
334335
}
335336
}
336337

337-
private static string GetLastSentSequenceFilePath()
338+
private static string GetLastSentSequenceFilePath(IAgentApplicationConfiguration agentConfig = null)
338339
{
339-
var bufferDir = Path.Combine(AppContext.BaseDirectory, "buffer");
340-
Directory.CreateDirectory(bufferDir);
341-
return Path.Combine(bufferDir, "mqttrelay_last_sent.seq");
340+
string baseDir = !string.IsNullOrEmpty(agentConfig?.DurableBufferPath)
341+
? agentConfig.DurableBufferPath
342+
: DirectoryBuffer;
343+
344+
if (!Path.IsPathRooted(baseDir))
345+
{
346+
baseDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, baseDir);
347+
}
348+
return Path.Combine(baseDir, LastSentSequenceFileName);
342349
}
343350

344351
private ulong GetLastSentSequence()
345352
{
346-
if (!_configuration.DurableRelay) return 0; // Default
347-
var path = GetLastSentSequenceFilePath();
353+
if (!_configuration.DurableRelay) return 0;
354+
var agentConfig = Agent?.Configuration as IAgentApplicationConfiguration;
355+
var path = GetLastSentSequenceFilePath(agentConfig);
348356
lock (_lastSentSequenceLock)
349357
{
350358
if (File.Exists(path))
@@ -359,7 +367,8 @@ private ulong GetLastSentSequence()
359367
private void SetLastSentSequence(ulong seq)
360368
{
361369
if (!_configuration.DurableRelay) return; // Default
362-
var path = GetLastSentSequenceFilePath();
370+
var agentConfig = Agent?.Configuration as IAgentApplicationConfiguration;
371+
var path = GetLastSentSequenceFilePath(agentConfig);
363372
lock (_lastSentSequenceLock)
364373
{
365374
File.WriteAllText(path, seq.ToString());

0 commit comments

Comments
 (0)