Skip to content

Commit

Permalink
Updated parameters to show SetSubscriptionDurable Functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Archie-Miller committed Oct 14, 2024
1 parent 4a76a03 commit 9fedb96
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
8 changes: 5 additions & 3 deletions Applications/ConsoleReferenceClient/ClientSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,12 @@ public bool SubscribeToDataChanges(ISession session, uint minLifeTime, bool enab
int subscriptionPublishingInterval = 1000;
int itemSamplingInterval = 1000;
uint queueSize = 10;
uint lifetime = minLifeTime;

if (enableDurableSubscriptions)
{
subscriptionPublishingInterval = 30000;
queueSize = 600;
queueSize = 100;
lifetime = 20;
}

// Define Subscription parameters
Expand All @@ -371,7 +372,8 @@ public bool SubscribeToDataChanges(ISession session, uint minLifeTime, bool enab
PublishingEnabled = true,
PublishingInterval = subscriptionPublishingInterval,
LifetimeCount = 0,
MinLifetimeInterval = minLifeTime,
MinLifetimeInterval = lifetime,
KeepAliveCount = 5,
};

session.AddSubscription(subscription);
Expand Down
26 changes: 17 additions & 9 deletions Applications/ConsoleReferenceClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ await FindUserCertificateIdentifierAsync(userCertificateThumbprint,
}
}

if ( enableDurableSubscriptions )
{
uaClient.ReconnectPeriodExponentialBackoff = 60000;
}

bool connected = await uaClient.ConnectAsync(serverUrl.ToString(), !noSecurity, quitCTS.Token).ConfigureAwait(false);
if (connected)
{
Expand Down Expand Up @@ -385,6 +390,7 @@ await samples.SubscribeAllValuesAsync(uaClient,
if (enableDurableSubscriptions)
{
quitTimeout = 150_000;
uaClient.ReconnectPeriod = 500_000;
}

NodeId sessionNodeId = uaClient.Session.SessionId;
Expand All @@ -394,27 +400,23 @@ await samples.SubscribeAllValuesAsync(uaClient,
samples.Browse(uaClient.Session);
samples.CallMethod(uaClient.Session);
samples.EnableEvents(uaClient.Session, (uint)quitTimeout);
bool isDurable = samples.SubscribeToDataChanges(
samples.SubscribeToDataChanges(
uaClient.Session, 60_000, enableDurableSubscriptions);
if ( isDurable )
{
// Need to control the reconnect
uaClient.ReconnectPeriod = 200_000;
}

output.WriteLine("Waiting...");

// Wait for some DataChange notifications from MonitoredItems
int waitCounters = 0;
int checkForWaitTime = 1000;
int closeSessionTime = checkForWaitTime * 35;
int restartSessionTime = checkForWaitTime * 65;
int closeSessionTime = checkForWaitTime * 15;
int restartSessionTime = checkForWaitTime * 45;
bool stopNotQuit = false;
int stopCount = 0;
while (!quit && !stopNotQuit && waitCounters < quitTimeout)
{
quit = quitEvent.WaitOne(checkForWaitTime);
waitCounters += checkForWaitTime;
if (isDurable)
if (enableDurableSubscriptions)
{
if (waitCounters == closeSessionTime)
{
Expand All @@ -433,6 +435,12 @@ await uaClient.DurableSubscriptionTransfer(
useSecurity: !noSecurity,
quitCTS.Token);
}

if ( waitCounters > closeSessionTime && waitCounters < restartSessionTime )
{
Console.WriteLine("No Communication Interval " + stopCount.ToString());
stopCount++;
}
}
}
}
Expand Down

0 comments on commit 9fedb96

Please sign in to comment.