Sportsbook Demo: Now in MQTT Flavor

Push Technology - March 24, 2021

MQTT is a publish-subscribe messaging protocol commonly used to connect Internet of Things (IoT) applications.

With the release of Diffusion 6.6, Diffusion supports clients connecting with MQTT 5.0. See the 6.6 manual for full details.

A wide range of IoT devices can connect directly to Diffusion, send and receive data, interact with other Diffusion clients, and benefit from Diffusion’s data wrangling features and rich security framework.

MQTT can be used as a lightweight alternative to the Diffusion SDK for simple publish-subscribe use cases, although MQTT connections cannot take advantage of the full range of features available when connecting using the SDK.

What is the Sportsbook demo?

Sportsbook is a demo bundled with the default on-premise Diffusion server installation.

Its purpose is to demonstrate Diffusion’s capability as a robust Intelligent Event Data Platform by modeling the kind of data flow a gaming firm would see while providing real-time odds for soccer betting.

Sportsbook demo UI

The original Sportsbook demo was implemented using the Diffusion JavaScript SDK.

To demonstrate the ease of linking an MQTT client with a Diffusion server, we have ported Sportsbook to use pure MQTT instead.

Running the MQTT Sportsbook demo

The MQTT Sportsbook demo is installed by default when you install Diffusion 6.6, alongside the  Diffusion based Sportsbook demo.

To run it, first download and install Diffusion from here. When installing, make sure “Demos & Examples” is ticked. Once installed, run diffusion.sh for Linux / Mac, or diffusion.bat for Windows.

In another terminal, run:
java -jar sportsbook-demo-publisher-jar-with-dependencies.jar under examples/demos/sportsbook.

Code similarities and differences

Fundamentally, the core code of the application remains unchanged; in fact, the only changes revolve around establishing the connection to the Diffusion server.

By ingesting the same properties.json file found in the original Javascript version of Sportsbook in its root directory, a connection is established using the mqtt.js library. The event listeners are then defined in a way that are as close as possible to the JavaScript version.

Diffusion SDK Top; MQTT Bottom

Here, the only differences lie in how the path selector is defined, and the definition of a cache object in the MQTT implementation. Whilst Diffusion uses a DSL to define a path selector, MQTT uses regex.

With Diffusion, each time a message is received, it is stored in its CBOR form in a local cache. This value is used to calculate the new value: a delta is taken between the new message value and the cached version. The original Sportsbook UI relied on this to present changes over time to the user.

MQTT does not send the previous value – nor does it keep a local cache like Diffusion, so a manual local cache had to be defined to mimic this behavior. Moreover, this cache retains the whole message, so the speed and bandwidth benefits of taking a delta are lost.

 

Diffusion SDK Left; MQTT Right

These blocks of code outline how each implementation connects to the Diffusion server. Other than using library specific methods to connect to the server, the general mechanism is the same; connect to the server using the given credentials and define a series of event listeners.

 

Diffusion SDK Top; MQTT Bottom

These blocks of code deal with handling incoming topic values from the server. As above, while the exact implementations differ due to library differences, the mechanisms are nearly identical. Note that the MQTT implementation has to manually assign a value to oldValue in order to cache previous values.

 

We hope this demo shows how easy it is to use MQTT with Diffusion 6.6. You can download and install Diffusion 6.6 now and try it out right away.


The Diffusion® Intelligent Event-Data Platform makes it easy to consume, enrich and deliver event-data in real-time across all network conditions. 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 bring innovative products to market faster by reducing the software development efforts using the low-code features. The Diffusion® Intelligent Event-Data Platform is available on-premise, in-the-cloud, or in a hybrid configuration. Learn how Push Technology can reduce infrastructure costs, and increase speed, efficiency, and reliability, of your web, mobile, and IoT application.

Learn More: View Blog Posts and Developer Resources

Share:

Check out these other resources

Info

Info Center

Case Studies, White Papers, and Tech Talk notes relating to Diffusion and the customers benefiting from using it.

Info

Quick Start Guide

Step-by-step guide to getting started fast with Diffusion or Diffusion Cloud.

Info

Diffusion Cloud

Get the facts and the details about our Diffusion Cloud platform.