You can build reliable, scalable real-time applications with Pega Platform™ without having to use additional components or third-party solutions. The Pega Platform provides a built-in notifications feature that application components can use to communicate in real time.
Based on the publish/subscribe (pub/sub) messaging pattern, this feature helps nodes in a cluster to push notifications to browser clients.
The use cases for real-time messaging and push notifications are numerous and include:
- Streaming data: From real-time dashboards to activity streams, streaming data is a key requirement for integrated applications.
- Online availability: From chat applications to online collaborators, knowing who is online and what their status is can enhance decision-making at an organizational level.
Real-time messaging in the Pega Platform is based on the pub/sub messaging pattern. In this pattern, messages are published to a topic that broadcasts the messages to all interested subscribers. Messages are delivered according to the best-effort delivery paradigm.
By default, the Pega Platform uses WebSockets to establish a connection with the browser client immediately after a requestor logs in. If the Pega Platform cannot establish a WebSocket connection, it uses long polling. The connection is active until the requestor logs out, is passivated, or is timed out.
Channels are named destinations (or topics) that can receive messages from a node and broadcast messages to all registered subscribers.
You can set up your own notification channel that can be subscribed to by any dynamic layout. You create a notification channel from the Notification channels landing page.
For example, Operator Presence is a notification channel to which all the operators publish their state and status changes. UI components can subscribe to this channel to get real-time status of logged-in operators without any repeated requests.
Any data source can publish messages to a notification channel in response to an event.
You can use the Publish-Notifications method in an activity to publish messages to a channel that is specified as a parameter. If the channel was configured to receive specific properties, only those properties are published. If not, all the top-level scalar and value list properties on the step page are published to the channel.
Publish activity in the Pega Platform
A real-time message is composed of top-level scalar and value list properties on a clipboard page. The page is encapsulated and sent to the channel. When the broadcasted message is received by a node, the context of the message is checked against the subscriptions available on the node. If the contexts match, the message is delivered in JSON format.
Clients interested in data changes triggered by events need to subscribe to a channel that is configured to receive those data changes. Subscribers can filter messages from a channel based on a specific property. For example, the my stock widget app should receive real-time updates only for pharmaceutical industry stocks (.pyIndustryType = "Pharma").
To subscribe to a channel, create an action set that is based on the On Load event. When specifying a callback action, avoid refreshing the same section because this can cause the dynamic layout to unsubscribe and subscribe again.
When a message is received on a server node, the subscriber determines whether the message context applies to any subscriptions on the node. If there are matching subscriptions, the specified callback actions are invoked.
You can debug the subscribe and publish operations if you enable the following loggers at debug level:
com.pega.pegarules.session.internal.serverpush – debug
com.pega.platform.message – debug
You can monitor real-time notifications in your application using the following MBeans:
Consider a contact center ticket system where team members and other stakeholders simultaneously update a work item. The various activities performed on this work item are maintained as a log file or social stream.
You can improve customer experience and team collaboration by configuring your application to receive instant updates from customers or when a high-priority ticket is assigned to a user.
- Identify the real-time data that you are interested in, for example, a comment by a customer (.pyMessage) on the work item or a high-priority item (.pyPriority="Critical") that should be immediately reflected in the feed or worklist.
- Create a notification channel to which the changes to a worklist or activity log are published. For example, you might create a notification channel PriorityTickets and CustomerUpdates based on your high-level class that contains the priority tickets and activity feeds.
- Configure the dynamic layout that holds your worklist and activity feed to subscribe to messages from PriorityTickets and CustomerUpdates with the required conditions.
Whenever a high-priority ticket is assigned to you, your dashboard is automatically updated. An update from a customer is instantly reflected in your feed.