Skip to content

Commit

Permalink
fix(real time read): added reconnect timeout loop and updated log levels
Browse files Browse the repository at this point in the history
resolves PRODSUP-4052
  • Loading branch information
roehlerw committed May 25, 2023
1 parent c9f7947 commit 4fd2816
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
14 changes: 14 additions & 0 deletions PluginSalesforce/API/Factory/PushTopicConnection.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading;
using CometD.NetCore.Client;
using Naveego.Sdk.Logging;
using Naveego.Sdk.Plugins;
Expand All @@ -13,6 +14,8 @@ public class PushTopicConnection
private readonly Listener _listener = null;
private readonly string _channel = "";

private CancellationTokenSource _cts;

public PushTopicConnection(BayeuxClient bayeuxClient, string channel)
{
_bayeuxClient = bayeuxClient;
Expand All @@ -21,6 +24,11 @@ public PushTopicConnection(BayeuxClient bayeuxClient, string channel)
}
public void Connect()
{
// force the client to reconnect after 30 minutes
_cts = new CancellationTokenSource();
_cts.CancelAfter(1800 * 1000);

// connect the client
_bayeuxClient.Handshake();
_bayeuxClient.WaitFor(1000, new[] { BayeuxClient.State.CONNECTED });
_bayeuxClient.GetChannel(_channel).Subscribe(_listener);
Expand All @@ -34,7 +42,13 @@ public void Disconnect()

public async IAsyncEnumerable<string> GetCurrentMessages()
{
if (_cts.IsCancellationRequested) {
Logger.Debug("request to disconnect stream requested");
Disconnect();
}

if (!_bayeuxClient.Connected) {
Logger.Debug("request to connect stream requested");
Connect();
}

Expand Down
2 changes: 1 addition & 1 deletion PluginSalesforce/API/Utility/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void OnMessage(IClientSessionChannel channel, IMessage message)
{
var convertedJson = message.Json;
_messages.Add(convertedJson);
Logger.Info($"Got message: {convertedJson}");
Logger.Debug($"Got message: {convertedJson}");
}

public void ClearStoredMessages()
Expand Down
2 changes: 1 addition & 1 deletion PluginSalesforce/DataContracts/RealTimeEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class RealTimeEvent
public DateTime CreatedDate { get; set; }

[JsonProperty("replayId")]
public Int32 ReplayId { get; set; }
public long ReplayId { get; set; }

[JsonProperty("type")]
public string Type { get; set; }
Expand Down

0 comments on commit 4fd2816

Please sign in to comment.