Topic mapping

It is common for the topic space on the source and destination to be different. The topic mapping string allows for the source topic to be mapped to the destination topic.

A replacement variable is of the form ${varname}. Any characters except replacement variables are copied to the destination topic. Where the replacement variable exists its value is copied into the destination topic.

Parts of the topic are delimited by a slash (/) and the portion of the topic before the first slash is part 0. Replacement variables of the form ${Topic#} where # is a number between 0 and 99 mean that the part of the topic that follows the specified number of slashes, and up to the next slash is copied to the destination topic string. If the name that is followed by an asterisk, for example, ${Topic3*} the value that is copied to the destination is the rest of the topic starting with the specified part.

Example:
Topic = iot-2/type/washer/id/123ABC567/evt/ThisEvent/fmt/json
TopicMap = wiotp/event/${Topic2}/${Topic4}/${Topic6}
Result = witop/event/washer/123ABCC567/ThisEvent
TopicMap = wiotp/event/%{Topic2*}
Result = wiotp/event/washer/id/123ABC567/evt/ThisEvent/fmt/json

A KeyMap uses the same syntax, but is used to form the Event Streams key. The key can be a simple string or can be JSON. It is best to use the JSON format replacement variables when creating JSON as this gives support for correctly quoting and escaping values. If JSON is directly encoded, it is necessary to escape several characters including quote marks.

Example:
Topic = "iot-2/type/washer/id/123ABC567/evt/ThisEvent/fmt/json",
KeyMap = {${JSON:type:Topic2},${JSON:id:Topic4},${JSON:event:Topic6},${JSON:time:TimeISO}} 
Result = {“type”:”washer”,”id”:”123ABC567”,”event”:”ThisEvent”,”time”: 
          ”2018-11-01T11:00:22.123Z”}