Diffusion enables the creation of scalable real-time solutions on mobile, browser or desktop. Our latest release, Diffusion 6.0, includes new features to simplify development of collaborative applications, like real-time text chat.
In this article, we’ll discuss a simple example chat application we developed to demonstrate three new Diffusion 6.0 features:
- Time series topics
- Topic persistence
- Topic notifications
Time series topics
The new time series topic type enables you to represent a sequence of events with a single topic. Each time series topic has a value type for the events it contains: int64, double, string, JSON, recordV2 or binary.
New values can be appended to the time series topic by multiple clients. They will be streamed to all subscribers of the topic in the same manner as with other topic types. Time series topics also retain a record of previous values which can be queried or updated and therefore used to create real time interactive applications which maintain a history of events.
The time series topic is a natural fit for many applications like chat or turn-based browser games, but also for creating applications which require retention of previous data points. These data points could originate from a topic that publishes prices or tracking data which can be collected and used for the purposes of data analysis or visualization.
Topic persistence is another new feature shipped with Diffusion 6.0. Topic persistence allows the Diffusion server to automatically store the full state of the topic tree to disk so that it can be quickly restored when the server is restarted. Combined with a time series topic, persistence means that the history of a topic can be stored on the server, and kept even through restarts.
Topic notifications enable a client to receive information about changes to the topic tree structure, without needing to receive topic values.
Example — Embedding live chat into a website
Building a chat application with these new Diffusion features is a straightforward process because a chat session can be implemented as a single time series topic, with each new message appended to the topic as an event.
In our example support chat application, a popup window has been embedded into a web page (we used the first World Wide Web page ever hosted at CERN) using HTML5 elements.
Here’s the code used to send a new chat message from the chat popup to the server:
Here’s the code used to make the chat popup receive and display new messages. The client registers a callback which appends all incoming messages to an HTML element with the id ‘chatmessages.’
To allow ‘agents’ to answer chats, we made a simple single page web application. The agent application uses topic notifications to subscribe to new chat sessions automatically.
The agent receives each user’s message history and can reply to their chats. With persistence enabled, the conversations are maintained even if the Diffusion server is restarted.
We use topic notifications to detect when a new chat session starts and update the agent view. When a new topic is added under the path /chat/chatsessions/, the addUser callback is called to add a representation of the
chat session to the agent interface.
The Diffusion Intelligent Data Mesh manages, optimizes, and integrates data among devices, systems, and applications. Push Technology pioneered and is the sole provider of real-time delta data streaming™ technology that powers mission-critical business applications worldwide. Leading brands use Push Technology to fuel revenue growth, customer engagement, and business operations. The products, Diffusion® and Diffusion Cloud™, are available on-premise, in-the-cloud, or in a hybrid configuration, to fit the specific business and infrastructure requirements of the applications operating in today’s mobile obsessed, everything connected world. Learn how Push Technology can reduce infrastructure costs, and increase speed, efficiency, and reliability, of your web, mobile, and IoT application.