Create a new named topic view.
If a view with the same name already exists the new view will update the existing view.
the name of the view
the specification of the view using the DSL
a Result that completes when a response is received from the server, returning the topic view created by the operation.
If the task fails, the Result will resolve with an error. Common reasons for failure, include:
specification
is invalid;
List all the topic views that have been created.
a Result that resolves when a response is received from the server, returning a list of views sorted by their creation order.
If the task fails, the Result will resolve with an Error. Common reasons for failure include:
Remove a named topic view if it exists.
If the named view does not exist the completable future will complete successfully.
the name of the view
a Result that resolves when a response is received from the server.
If the task fails, the Result will resolve with an Error. Common reasons for failure include:
Topic view feature.
This feature provides a client session with the ability to manage topic views.
A topic view maps one part of the server's topic tree to another. It dynamically creates a set of reference topics from a set of source topics, based on a declarative topic view specification. The capabilities of topic views range from simple mirroring of topics within the topic tree to advanced capabilities that include publication of partial values and throttling the rate of publication.
Each reference topic has a single source topic and has the same topic type as its source topic. Reference topics are read-only (they cannot be updated), nor can they be created or removed directly. Otherwise, they behave just like standard topics. A client session can subscribe to a reference topic, and can fetch the reference topic's current value if it has one.
The source topics of a topic view are defined by a topic selector. A reference topic is created for each source topic, according to the topic view. If a source topic is removed, reference topics that are derived from it will automatically be removed. If a topic is added that matches the source topic selector of a topic view, a corresponding reference topic will be created. Removing a topic view will remove all of its reference topics.
Topic view specifications
The following is a simple topic view specification that mirrors all topics below the path
a
to reference topics below the pathb
.A topic view with this specification will map a source topic at the path
a/x/y/z
to a reference topic at the pathb/x/y/z
. The specification is simple, so the reference topic will exactly mirror the source topic.A general topic view specification comprises several parts:
Source topic clause
The source topic clause begins with themap
keyword and is followed by a topic selector. These topic selectors follow the same parsing rules as other topic selectors. When evaluating a topic view, topics in the topic tree that match the source topic selector are considered, with the following exceptions:Both SLAVE and reference topics are valid source topics. In particular, chaining of topic views is supported; that is, a reference topic created by one topic view can be the source topic of another topic view. Additionally, a reference topic can be the master topic of a slave topic, or the source topic of a routing topic subscription.
Path mapping clause
The path of a reference topic is derived from the source topic according to the topic view path mapping. The path mapping allows the source topic path and the value of the source topic to determine the path of the reference topic.A path mapping clause begins with the
to
keyword and is followed by a path mapping template. A path mapping template is a topic path with embedded directives. Directives are evaluated when creating the topic reference and substituted into the topic path. Directives are delimited by angle brackets (<
,>
) and consist of the name of the directive and a list of parameters. The parameter list is comma-separated and surrounded by parentheses ((
,)
).Two path mapping directives are supported:
<path(start, number)>
, or<path(start)>
when the number of parts parameter is omitted.For example, given the source path
a/b/c/d
, the source path directive<path(1, 2)>
is mapped to the reference topic pathb/c
, and the source path directive<path(2)>
is mapped to the reference topic pathc/d
.scalar
and are parameterized by a single JSON pointer that extracts a scalar value from the source value. A scalar value is a string, a number,true
,false
, ornull
, that is, anything other than an array or a object. If the JSON pointer does not refer to a scalar value in the source value, no reference topic will be created. This includes the cases where the JSON pointer refers to an array or an object), or when no part of the source value is selected.Deriving the reference topic paths from part of the source topic value effectively creates a secondary index on the value. For source value directives to work efficiently, the selected scalar values should be relatively stable. If an update to the source topic changes the selected scalar value, the corresponding reference topic will be removed and a new reference topic will be created.
For example, given a source value of
and the source value directive
currency/<scalar(/balance/currency)>/account/<scalar(/account)>
, the reference topic path will becurrency/USD/account/1234
.If the extracted value is a string, it is copied literally to the reference topic path. A value that contains path separators (
/
) will create a reference topic path with more levels than the path mapping template.An extracted value of
null
will be copied to the reference topic path as the string"null"
.Topic property mapping clause
The topic specification of a reference topic is derived from the topic specification of the source topics. A reference topic has the same topic type as its source topic.The topic properties of a reference topic are derived from the source topic. Some topic properties can be tuned using the optional topic property mapping clause. The following table describes the behavior for each topic property.
TIME_SERIES_RETAINED_RANGE
property. The retained range of a reference time series topic will be constrained to be no greater than that of its source topic.A topic property mapping clause begins with the keywords
with properties
and consists of a comma-separated list of topic property keys and values, each separated by a colon. For example, the following topic view specification maps all topics below the patha
to reference topics below the pathb
, and disables both conflation and compression for the reference topics.Topic value mapping
The value of a reference topic is derived from the source topic according to the topic view value mapping. By default, a reference topic's value is the same as its source topic.For
JSON
source topics, the optional topic value mapping clause can be used to extract part of the source value. A topic value mapping begins the keywordas
and is followed by a value directive. A value directive is delimited by angle brackets (<
,>
), and consists of thevalue
keywords and a single JSON pointer parameter. The JSON pointer selects the part of the source value to copy.For example, given a source value of
and the value mapping clause
as <value(/balance)>
, the reference topic value will beTopic value mappings are often used with path value mappings. For example:
Throttle clause
The optional throttle clause can be used to constrain the rate at which a reference topic is updated when its source topic is updated. The primary application of a throttle clause is to restrict the number of updates sent to reference topic subscribers, reducing network utilization or the processing each subscriber must do. Throttling also restricts the rate at which client sessions can observe changes to reference topic values using the fetch API.The throttle clause has the form
throttle to X updates every period
, where X is a positive integer, and period is a positive integer followed by a time unit which is one ofseconds
,minutes
, orhours
.For example, the following topic view specification maps all topics below the path
a
to reference topics below the pathb
, but updates the value of each reference topic at most twice every five seconds:To improve readability, the throttling clause allows
1 update
as an alternative to1 updates
, andevery second
as an alternative toevery 1 seconds
(and so on, for other time units). For example, the following topic view specification maps all topics below the patha
to reference topics below the pathb
, but updates the value of each reference topic at most once every hour:The throttle clause is only applied when a source topic is updated more frequently than the configured rate. If a source topic is updated less frequently, updates are passed on unconstrained. If the rate is exceeded, a reference topic will not be updated again until the configured period has expired. At this time, the reference topic will be updated based on the source topic updates that happened in the interim, and a single value will be published. Thus, a throttle clause provides topic-scoped conflation.
The throttle clause is ignored for time series topics because time series updates do not support efficient conflation. Updates to source time series topics are passed on immediately to the corresponding reference topics, regardless of any throttle clause.
Quoting and white space
Topic selectors and path mapping templates can be quoted or unquoted. They are quoted using the single quote mark. To include whitespace, single quotes or literal opening angle brackets they must be quoted. In quoted selectors and templates single quotes, literal opening angle brackets and backslashes must be escaped with a single backslash. In templates the opening angle bracket should be unescaped when beginning a directive. Characters in unquoted selectors and templates cannot be escaped.Any whitespace can be used to separate keywords, statements and clauses.
Dealing with topic path conflicts
Reference topics have a lower priority than normal topics created through the API, including replicas of normal topics created by topic replication or fan-out. A reference topic will only be created if no topic or reference topic is already bound to its derived topic path.
Topic views have a precedence based on order of creation. If two topic views define mappings the same topic path, the earliest-created topic view will create a reference topic. If a topic view is updated, it retains its original precedence.
Topic view persistence and replication
Reference topics are neither replicated nor persisted. They are created and removed based on their source topics. However, topic views are replicated and persisted. A server that restarts will restore topic views during recovery. Each topic view will then create reference topics based on the source topics that have been recovered.
The server records all changes to topic views in a persistent store. Topic views are restored if the server is started.
If a server belongs to a cluster, topic views will be replicated to each server in the cluster. Topic views are evaluated locally within a server. Replicated topic views that select non-replicated source topics can create different reference topics on each server in the cluster.
Access control
The following access control restrictions are applied:
Accessing the feature
This feature may be obtained from a session as follows:
6.3