dharnendra | 2020-03-13 15:32:15 UTC | #1
Hi,
We do have one .net web application where we are adding subscription for Notification Handler and Presence.
It then do send the notification to web application which is working fine. Now the issue coming when it remains idle. Notification are not coming from pure cloud, after some idle time. I am not getting any way on how we can create persist connect with pure cloud.
Can any one help on it?
tim.smith | 2020-03-13 15:33:34 UTC | #2
Make sure you're following the Notification Service Usage Guidelines. Are you still receiving heartbeats on the websocket?
dharnendra | 2020-03-16 13:05:59 UTC | #3
I am using this code for it. public void ConnectToSocket(string genesysId) { try {
handler = new NotificationHandler(); handler.AddSubscription($"v2.users.{genesysId}.presence", typeof(PresenceEventUserPresence)); handler.AddSubscription($"v2.users.{genesysId}.conversations", typeof(ConversationEventTopicConversation)); *handler.Ping();* HandleSocketNotofications();
SocketConnected = true; } catch (Exception ex) { SocketConnected = false; } }
I am not sure how I can achieve it through this code.I am not using API but using .net SDK.
tim.smith | 2020-03-13 15:54:44 UTC | #4
Are you still receiving heartbeats on the websocket?
dharnendra | 2020-03-16 13:00:09 UTC | #5
Hi Tim,
I am not finding way on how to check heartbeats through web application. I am using purecloud .net SDK. Can you provide me any link containing code of same please?
I did added " handler.Ping();" code after the handler.addsubscription. Although I am not having anything under its event handler handler.NotificationReceived += (data1) =>
Another way I just found that if I add this code handler.WebSocket.OnMessage += WebSocket_OnMessage; then under it, I am able to found the heartbeat but I am not getting that on which condition I can re-subscribe the channel and how I can have the userID in this function?
tim.smith | 2020-03-17 14:28:49 UTC | #6
The documentation for the ping method mentions this:
handler.AddSubscription("channel.metadata", typeof(ChannelMetadataNotification));
tim.smith | 2020-03-17 15:42:54 UTC | #7
Are you creating multiple instances of the NotificationHandler class? This thread sounds similar:
https://developer.mypurecloud.com/forum/t/notificationhandler-c-stops-sending-notification/7360/1
dharnendra | 2020-03-18 09:49:16 UTC | #8
Hi Tim,
Thanks for the response. I am using below code to reconnect the subscription. If I am not having pong or heartbeat then I remove subscription and adding the subscription again.
handler.NotificationReceived += (data1) => { msg = JsonConvert.SerializeObject(data1, Formatting.Indented); if (data1.TopicName == "channel.metadata") { //RaiseEvent(msg, "", false); //Json if (!msg.Contains("pong") && !msg.Contains("WebSocket Heartbeat"))//either pong or heartbeat { //reestablish code handler.RemoveAllSubscriptions(); ConnectToSocket(GenesysAgentId, true);//reconnect the subscriptions } }
Below is the connecttoSocket method. I am using same handler in case of re-subscription.
public void ConnectToSocket(string genesysId,bool IsReconnect) { try { if(!IsReconnect) handler = new NotificationHandler(); handler.AddSubscription($"v2.users.{genesysId}.presence", typeof(PresenceEventUserPresence)); handler.AddSubscription($"v2.users.{genesysId}.conversations", typeof(ConversationEventTopicConversation)); handler.AddSubscription("channel.metadata", typeof(ChannelMetadataNotification)); handler.Ping(); HandleSocketNotofications();
SocketConnected = true; } catch (Exception ex) { SocketConnected = false; } } I was not able to test it out but seems right approach as there is no effect in existing functionality. Not sure whether its work in case of expiration.
tim.smith | 2020-03-19 21:59:10 UTC | #9
How long elapses after subscribing until notifications stop? Note that the usage guidelines state that channels will only remain active for 24 hours after the last update to the subscribed topics.
Michael.Shrall | 2020-03-27 12:15:27 UTC | #10
@tim.smith - couple of questions on handling the notification ping/pong failure or channel general timeout in 24 hours.
- Does the NotificationHandler class need to be recreated when the ping/pong failure occurs? Looking at the implementation of the notificationhandler, it appears the channel/connection is only established in the constructor. Calling RemoveAllSub and then addSub isn't reestablishing any connection.
- If #1 is accurate, does that hold true for the general timeout logic as well where it should recreate the NotificationHandler class prior to the 24 hour timeout?
tim.smith | 2020-03-27 13:09:53 UTC | #11
If the socket connection fails for any reason, the NotificationHandler class should be recreated.
Stefan_Eyckmans | 2020-04-15 10:54:47 UTC | #12
I would also like to note here that sometimes the websocket connections are closed because of maintenance or whatever at purecloud side, so not always because of idle users.
I integrated a check that pings the websocket every x seconds and if I do not get a response I recreate the handler. I also listen to the OnClose event and basically do the same. Only when the WCF application is in a state where the user is shutting down the application I will not reconnect when the OnClose event is called.
Saw the mechanism kick in earlier this week, seems to work since I received no complaints about users not receiving any notifications anymore
dharnendra | 2020-04-28 10:31:40 UTC | #13
Hi,
Sorry for late response. I just would like to know couple of things.
After the above implementation, I am not getting 'Heartbeat' after 30 minutes. It should generally send heartbeat till 24 hrs but its not. What should be the reason for it?
Further I did added within condition that if the message do not have heartbeat it do resubscribe the channel but that condition never get called. Seems there would be no message coming after 30 mins or so.
I also added handler for close ' handler.WebSocket.OnClose += WebSocket_OnClose;' but its not getting called .
Not sure what would be the issue and how should i resolve this issue. Any suggestions?
tim.smith | 2020-04-28 16:07:58 UTC | #14
dharnendra, post:13, topic:7344
I am not getting 'Heartbeat' after 30 minutes
If you're no longer getting heartbeat messages, it means the WebSocket is no longer open. You should close it and reconnect. Resubscribing is not related to this as the issue is with the actual transport connection, not the logical subscriptions on the server.
dharnendra, post:13, topic:7344
I also added handler for close ' handler.WebSocket.OnClose += WebSocket_OnClose;'
That will be raised if the WebSocket is gracefully closed, which often doesn't happen with WebSockets.
dharnendra, post:13, topic:7344
Not sure what would be the issue and how should i resolve this issue.
If this is a persistent problem, check with your networking team to troubleshoot. Opening a case with Genesys Cloud Care may be useful, but they cannot help you troubleshoot your local network or connection to the internet.
dharnendra | 2020-04-28 18:59:52 UTC | #15
tim.smith, post:14, topic:7344
If you're no longer getting heartbeat messages, it means the WebSocket is no longer open. You should close it and reconnect. Resubscribing is not related to this as the issue is with the actual transport connection, not the logical subscriptions on the server.
How should I do it and at which place ? Should I use something like Timer to check constantly the status if the socket is closed? I am not able to understand the implementation approach to resolve it.
Further its persistent problem. I am able to reproduce almost all times and not having hear beat after 20-30 mins duration.
tim.smith | 2020-04-29 15:28:29 UTC | #16
Your code will need to keep track of the timestamp when it last received the heartbeat. It will then need to have a timed bit of code that checks to see if the last timestamp is more than 30 seconds old (give it a few extra seconds to prevent being overzealous if the heartbeat is a second late). If it detects it's been too long. close the socket and reconnect it. The websocket object is exposed on the notification handler.
system | 2020-05-30 15:42:30 UTC | #17
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.
This post was migrated from the old Developer Forum.
ref: 7344