Substitution Expressions Overview
Substitution expressions are a Solace-specific expression language used to replace specific text attributes (request targets, request headers, etc.) with system generated output.
For example, suppose your deployment warrants using REST Delivery Points (RDPs) to send messages into storage services such as Azure Storage, Amazon S3, or Google Cloud Storage. This requires sending each message to a unique target, preferably with that uniqueness coming from the message topic, metadata, or the current time. To enable this, you could embed a substitution expression into the request target that configures the system to modify the target based on the data (topic, current time, etc.) from each incoming message.
A substitution expression consists of either a literal or a function call. Function call parameters can be any substitution expression that is of the appropriate type.
When embedded in text attributes, substitution expressions are delimited by ${
and }
. Only close braces outside of string literals end a substitution expression; there is no special escaping of braces required within a substitution expression. To include ${
in the text, a substitution expression can be used. For example, the ${
can be encoded as ${"$"}{
.
Any substitution expression that isn't valid results in an error at configure time. You can view error message details through all available monitoring interfaces (Broker Manager, CLI, SEMPv1, and SEMPv2).
Substitution Expression Functions
Substitution expression functions return a value and possibly take parameters. The currently available functions and whether they are applicable to RDP, Kafka sender, or Kafka receiver objects, are listed in the following table.
Function parameters and return values have specified types. A string may be passed in anywhere bytes are accepted; there are no other automatic conversions. The available types are:
-
integer: a 64-bit integer value (range: -9223372036854775808 through 9223372036854775807).
-
string: a UTF-8 encoded string.
-
bytes: a sequence of 0 or more bytes.
The integer timestamp parameter passed to all the time functions (utcYear, utcDate etc.) must be in milliseconds.
Function Name | Usage | Parameter Types | Return Type | Context | Description | ||
---|---|---|---|---|---|---|---|
RDP | Kafka | ||||||
Sender | Receiver | ||||||
topic |
|
integer |
string |
Returns part or all of the Solace
message destination topic. If N is positive, returns the Nth
field, numbering from 1. If N is negative, returns
the Nth field from the end of the topic. If N is
0 or not specified, returns the entire topic string. If the selected
field doesn't exist, returns the empty string. For example, if the
topic was |
|||
kafkaTopic |
kafkaTopic([N, separator])
|
integer, string |
string |
Returns the topic from a Kafka message. If N is provided, separator will be used as the topic level separator. The separator is required as Kafka does not define this (although by convention dot and underscore are common).
|
|||
now |
|
N/A |
integer |
Returns the current time in milliseconds from
midnight, January 1, 1970 UTC. For example, if the time were Mon 22 Jun 2020 13:13:02.123
EDT, the value returned would be |
|||
senderTimestamp |
|
N/A |
integer |
Returns the |
|||
kafkaTimestamp |
|
integer |
Returns the timestamp message field from the Kafka message. |
||||
ts |
|
N/A |
integer |
If the |
|||
utcDate |
|
string, integer |
string |
Returns the date portion of the
timestamp in UTC, formatted as |
|||
utcYear |
|
integer |
string |
Returns the four digit UTC year.
If timestamp is omitted, the value returned by |
|||
utcMonth |
|
integer |
string |
Returns the two digit UTC month.
If timestamp is omitted, the value returned by |
|||
utcDay |
|
integer |
string |
Returns the two digit UTC day.
If timestamp is omitted, the value returned by |
|||
utcTime |
|
string, integer |
string |
Returns the time portion of the
timestamp in UTC, formatted as |
|||
utcHour |
|
integer |
string |
Returns the two digit UTC hour.
If timestamp is omitted, the value returned by |
|||
utcMinute |
|
integer |
string |
Returns the two digit UTC minute.
If timestamp is omitted, the value returned by |
|||
localDate |
|
string, integer |
string |
Returns the date portion of the
timestamp in the broker's local time zone, formatted as |
|||
localYear |
|
integer |
string |
Returns the four digit year
portion of the specified timestamp in the broker's local time zone. If timestamp is
omitted, the value returned by |
|||
localMonth |
|
integer |
string |
Returns the two digit month
portion of the specified timestamp in the broker's local time zone. If timestamp is
omitted, the value returned by |
|||
localDay |
|
integer |
string |
Returns the two digit day portion
of the specified timestamp in the broker's local time zone. If timestamp is
omitted, the value returned by |
|||
localTime |
|
string, integer |
string |
Returns the time portion of the
timestamp in the broker's local time zone, formatted as |
|||
localHour |
|
integer |
string |
Returns the two digit hour
portion of the specified timestamp in the broker's local time zone. If timestamp is
omitted, the value returned by |
|||
localMinute |
|
integer |
string |
Returns the two digit minute
portion of the specified timestamp in the broker's local time zone. If timestamp is
omitted, the value returned by |
|||
second |
|
integer |
string |
Returns the two digit second
portion of the specified timestamp. If timestamp is omitted,
the value returned by |
|||
millisecond |
|
integer |
string |
Returns the three digit millisecond
portion of the specified timestamp. If timestamp is omitted,
the value returned by |
|||
unixTime |
|
integer |
integer |
Returns the number of seconds
since midnight, January 1, 1970 UTC for the specified timestamp, ignoring
leap seconds. This is known as unix time or epoch time. For
example, if the provided timestamp was for Mon 22 Jun 2020 13:13:02.123 EDT,
the value returned would be |
|||
randomBytes |
|
integer |
bytes |
Returns N cryptographically random bytes. N must be a positive integer less than 100. |
|||
uuid UUID |
|
N/A |
string |
Returns a new UUID. The |
|||
base32 BASE32 base32NoPad BASE32NoPad |
|
bytes |
string |
Returns the provided data (which
can be of type string or bytes) encoded as base32. There are four
variants, for the four combinations of uppercase/lowercase and padding.
The variants that start with base32 will produce lowercase output; the
variants that start with BASE32 will product uppercase output. The
variants that end with |
|||
base64 base64NoPad |
|
bytes |
string |
Returns the provided data (which
can be of type string or bytes) encoded as base64. The |
|||
base64Url base64UrlNoPad |
|
bytes |
string |
Returns the provided data (which
can be of type string or bytes) encoded as base64url. The |
|||
hex HEX |
|
bytes |
string |
Return the provided data (which
can be of type string or bytes) encoded as hexadecimal (base16).
The |
|||
urlEncode |
|
bytes, string |
string |
Returns the provided data (which can be of type string or bytes) URL encoded: any characters that are not unreserved characters according to RFC 3986 section 2.3 are percent-encoded (with the hexadecimal digits A-F in uppercase as per that specification), unless the character is specified in the exceptions string. If exceptions is not provided, it defaults to the empty string. |
|||
senderId |
|
N/A |
string |
Returns the Solace |
|||
userPropertyAsString |
|
string |
string |
Returns the propertyName (a case-sensitive string) user property value as a string. Returns the empty string if there is no user property with the specified name. If there is more than one user property with the specified name, only one of them is returned (it is undefined which one).1 |
|||
kafkaHeader |
|
string |
bytes |
Gets a header field from the Kafka message. Behaviours for missing or duplicated headerName is the same as |
|||
kafkaHeaderAsString |
|
string |
string |
Returns the same vale as |
|||
msgType |
|
N/A |
string |
Returns the Solace Application
Message Type (a string). Note that there are several different things
that message type can refer to. In this context it is an
arbitrary value set by the client and passed along but otherwise ignored by
the broker. In JMS it is accessed as |
|||
msgId |
|
N/A |
string |
Returns the Solace application message ID, a string, or an empty string if the property is not set. This property is not automatically generated by the event broker and must be set by the publisher application.1 |
|||
sequenceNumber |
|
N/A |
integer |
Returns the sequence number (an integer) of the message.1 |
|||
correlationId |
|
N/A |
string |
Returns the Solace correlation ID (a string) of the message.1 |
|||
partitionKey |
|
N/A |
string |
Returns the Solace partitioned queue key of the message.1 |
|||
kafkaPartitionKey |
|
N/A |
bytes |
Returns the Kafka partition key of the message as bytes. |
|||
kafkaPartitionKeyAsString |
|
N/A |
string |
Returns the same value as |
|||
kafkaPartitionNumber |
|
N/A |
integer |
Returns the partition number the message was received from. |
|||
kafkaPartitionOffset |
|
N/A |
integer |
Returns the partition offset of the message. |
|||
replace |
|
string, string, string, integer |
string |
Returns source with string old replaced with new, up to count number of times starting from the first (or last if count is negative). If count is not provided, all occurrences of old are replaced. While of general use, this has been added to convert Kafka Topics (with dots or underscores) to Solace Topics (with slashes). |
|||
withDefault |
|
string, string |
string |
Returns value unless value is the empty string, in which case it returns default. |
1—These values map to specific fields in non-SMF APIs.
- SMF to AMQP Conversions
- SMF to MQTT 5.0 Conversions
- SMF to MQTT 3.1 Conversions
- SMF to JMS Conversions
- SMF to HTTP Conversions
- SMF to HTTP Request Conversions
- SMF to Kafka Conversions
Substitution Expression Processing Examples
The following table lists several examples that illustrate how PubSub+ event brokers process substitution expressions. The examples assume a message arriving at January 2, 2006 3:04:05.123 pm with the following data:
-
topic=t/v1/DE/sk/escalator/1,2/sk_1.x/DE12345/raw
-
sender timestamp=January 2, 2006 3:04:04.987 pm
-
"author" user property=Jane "The Bear" Doe
-
In specific contexts in which substitution expressions are enabled, further processing may happen after substitution expression evaluation. For example, after substitution processing request targets will have spaces and non-ASCII characters percent-encoded to ensure that the target is valid.
-
Line breaks and indentation in the following examples are for readability only.
Input | Output |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Text Attributes That Can Contain Substitution Expressions
The following text attributes can contain substitution expressions:
-
RDP POST request targets, if substitution expression evaluation is configured. For more information, see Managing REST Delivery Points.
-
RDP request headers. For more information, see Managing REST Delivery Points.
-
Kafka receiver topic bindings (SMF topic generation). For more information, see Configuring SMF Topic Generation.
-
Kafka receiver topic bindings (partitioned queue key generation). For more information, see Configuring Partition Key Generation.
-
Kaka sender queue bindings (Kafka partition key generation). For more information, see Configuring Kafka Partition Key Generation.