Getting started with JSON & Binary in the JS client

With the release of Diffusion 5.7 two new topic types have been introduced; JSON & Binary. The former is especially useful for users of the JavaScript client, since JSON is the defacto standard for handling data in web-applications and enjoys native support in JS.  This article will go through some simple examples of using these new topic types, and explain where best to use them.

Data Types

JSON and Binary topics introduce the notion of datatypes. These are fully explained here, but in essence provide consistent guarantees around data and operations that can be performed on that data, such as creating deltas.

Datatypes are used in the API to derive values for use in updating topics, and also to create value streams for a particular set of topics. The API exposes these as part of the top-level diffusion namespace.

https://gist.github.com/push-gists/5ca0c905faca282331c2f2cd7b6ae4f8

To subscribe to a topic and receive datatype values, one creates a stream as normal, and then specialises it by providing the datatype to Stream#asType. Listeners for value, subscribe & unsubscribe events can then be bound. It’s important to note that only events for topics that are of the same datatype will be emitted.

https://gist.github.com/push-gists/311ca9f039529a006c706731cdb06000


Further reading

The Diffusion Data logo

BLOG

React PubSub using Diffusion Websocket Server

July 08, 2024

Read More about React PubSub using Diffusion Websocket Server/span>

BLOG

Unlocking the Value of ISO 27001 Certification: A Journey of Security and Continuous Improvement

March 25, 2024

Read More about Unlocking the Value of ISO 27001 Certification: A Journey of Security and Continuous Improvement/span>

The Diffusion Data logo

BLOG

Creating a WebSocket Server for PubSub

June 28, 2024

Read More about Creating a WebSocket Server for PubSub/span>