Using Topic Views 1: Mapping Topics

Introduced in Diffusion 6.3, topic views provide a view of one part of the topic tree from another, creating new topics that reflect their source topics. In the simplest case, a topic view mirrors the source topics without changing them, but a topic view can also adapt the topic path and topic content, or throttle the rate of updates.

In this series of tutorials, we will walk you through a number of use cases for topic views, from simple to complex. In this chapter we introduce topic views that map one topic to appear in another location.

The utility of a topic view is best explained by example, but first some terminology: a topic view draws on source topics, to create reference topics.

Sessions subscribe to or fetch from a reference topic in the same way as any other topic. Reference topics cannot be directly updated; instead a reference topic’s value is derived from the value of the source topic.

You can create topic views via the API using any of the Diffusion SDKs. However, the web-based Diffusion monitoring console is the easiest place to get started with them.

Mapping topic to topic

Start with a fresh Diffusion server. Ensure the Sportsbook demo is deployed (you can deploy the demo by copying ./demos/sportsbook.dar to ./deploy).

  • Start the server and log into the Diffusion console as admin.
  • Open the Topics tab.
  • Browse to a single Football topic: in this case, we will use Demos/Sportsbook/Football/England/Premier League/Manchester United vs Arsenal. The sports book demo topics are semi random, so pick another topic that covers Arsenal if they’re not playing Manchester United.
  • Open the Topic Views tab.
  • Add a new topic view named Highlights/Arsenal, with the specification map "Demos/Sportsbook/Football/England/Premier League/Manchester United vs Arsenal" to "Highlights/Manchester United vs Arsenal".
  • Click Add.
  • Open the Topics tab.
  • Find the new topic Highlights/Manchester United vs Arsenal.
  • Click info to see the content. Notice the topic property _VIEW tying this reference topic back to the topic view.

This looks much like the older slave topic type. However, we will see later how a topic view is much more capable. We can illustrate its potential by using some of the power of topic selectors.

First, some more terminology about topic view specifications:

Source topic clause: The part of the specification that identifies the source topics. In the current example: map "Demos/Sportsbook/Football/England/Premier League/Manchester United vs Arsenal". This example is wrapped in quotes as the selector contains spaces, but otherwise it need not be.

Path mapping clause: The part of the specification that instructs where (and with what) to build the reference topics. In the above example: to "Highlights/Manchester United vs Arsenal". Notice the quotes to handle a path containing spaces.

Mapping topic to topic, intelligently

In the prior example, we mapped the Arsenal game topic to a Highlights topic section, but this depends on knowing on the exact path to the topic we want to map, that is, knowing exactly who Arsenal are playing and in which league. In this section, we will adjust the topic view specification to make it less brittle.

    • Open the Topic Views tab.
    • Edit the existing topic view Highlights/Arsenal.
    • Adjust the specification to map "?Demos/Sportsbook/Football/England/.*/.*Arsenal.*" to "Highlights/<path(5)>".
    • Click Replace.

You can now open the Topics tab and verify that the Arsenal topic exists under topic Highlights – whoever they’re playing.

There are a few points to focus on here:

  1. We prefixed a question mark to the topic selector.
  2. We replaced the final pieces of the selector with the regular expressions .* and .*Arsenal.*.
  3. The path mapping clause now includes the source path directive <path(5)>.

The question mark prefix upgrades the topic selector to a split path topic selector, which can embed regular expressions. The source path directive can be read as “everything from step 5 onward from the source path”. Note that the source path directive is zero indexed. Consequently <path(0)> replicates the entire source path.

By using a split path topic selector and a source path directive, we now have a topic view that maps any Arsenal game topic to a reference topic under Highlights/, regardless of the opposition or league.

Summary

Using the simplest form of topic views we have mapped single topics from their origin into another place in the topic tree. Using the power of the topic selector we have made the topic view map the topic regardless of its unpredictable location.

Next: Mapping topic branches.