Topic mapping function

To map the topic path from a source Diffusion topic to a target Diffusion topic, the Diffusion server topic view path directive approach is used.

Using the mapping function, parts of the source Diffusion topic path will be extracted and another topic path constructed for target topics. The mapping function comprises path fragments and path directives. A path fragment is a section that is extracted as it is. It may contain the path separator character /. A path directive is an expression of format <path(start,length)>. It is used to select parts of the source path to be reused in the mapped topic path. start is mandatory and specifies the index of the source path to start from, and length specifies the number of parts to include from the start index. The length of the expression is optional. If it is missing, or '0' is specified, or a number that specifies a length longer than the end of the source path, the selection extends to the end of the source path. The start starts from 0, i.e., the index of the first part of the source path is 0.

With the above definition, below are a couple of examples of mapping a source topic path to a target topic path using the specified mapping function.

Topic mapping functions examples
Mapping function Source topic path Mapped target topic path

<path(0)>

a/b/c/d

a/b/c/d

accounts/<path(0)>

a/b/c/d

accounts/a/b/c/d

accounts/<path(0,1)>

a/b/c/d

accounts/a

accounts/<path(0,0)>

a/b/c/d

accounts/a/b/c/d

accounts/<path(0)>/final

a/b/c/d

accounts/a/b/c/d/final

accounts

a/b/c/d

accounts

dog/<path(0,1)>/cat/<path(3)>

a/b/c/d

dog/a/cat/d

The start and length parameters in the path directive should be positive numbers. If start fails to find the corresponding part in the source path, the target topic construction from the source topic fails, preventing the publication of an update from the source topic. For example, in the given source path a/b/c/d, if the mapping function is <path(5)>, there is no part at index 5 in the source path. Hence, the updates from the topic a/b/c/d will fail to be processed, and an error will be logged.

The default topic mapping function used in the service types is <path(0)>, i.e., the same path will be mapped for the target path (except for hybrid services, where setting the same target path will cause an error and prevent the service to be started).