Sending Notifications from the Server to Client Applications
Various business scenarios require sending notifications from the server to a client application: notifying about the completion of a report requested by the client, the completion of complex calculations on the server, etc.
Currently, this is done through periodic requests from the client to the server to get up-to-date information. This can lead to a significant volume of server calls, which, in turn, can negatively impact performance for end-users. This task can also be solved using the Collaboration System, but this solution may be excessive if users do not need all of the Collaboration System's functionality.
We have often been asked to improve this situation. With version 8.3.26, you can send notifications to clients from the server without using the Collaboration System.
We have implemented the ClientNotificationManager object, which allows sending notifications from the server to client sessions. Here are the methods of the new object (a detailed description of the methods and their parameters will be available in the documentation):
- ConnectHandler(, ). This client method connects a client notification handler. If the Key parameter is set to a string value, this string value can be used to selectively disable handlers. If Key is set to undefined, the handler will be called for all received notifications.
- DisableHandler() This client method disables a client notification handler. If Key is set to undefined, all handlers are disabled.
- SendNotification(, , ). This server method sends a notification to selected client sessions (if the Recipients parameter is filled with an array of session numbers obtained from InformationBaseSession.SessionNumber) or to all client sessions.
The ClientNotifications property of type ClientNotificationManager has been added to the global context.
The ParentSessionNumber property has been added to the BackgroundJob object. It contains the number of the parent session for the background job from which this background job was started. This will allow sending a notification from a background job to the client who is waiting for the result of this background job.
An important feature of the new mechanism is the guaranteed delivery of information to the client session (the session, not the user!). That is, if the send method is executed on the server, then regardless of the future status of the server processes (termination of cluster components or worker processes), an attempt will be made to deliver this notification as long as the client session exists.
With this new mechanism, you can send notifications from the server to client applications with a small amount of application code and with minimal load on network and hardware resources.