Skip to content

Commit 2977771

Browse files
authored
Merge pull request #2404 from ably/edu-1687-routing-conflation-keys
[EDU-1687] Add message routing and conflation syntax info
2 parents 4d12766 + d8e22cc commit 2977771

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

content/messages/index.textile

+53-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ redirect_from:
1818
Messages contain the data that a client is communicating, such as the contents of a chat message. Clients publish messages on "channels":/channels, and these messages are received by clients that have "subscribed":/pub-sub#subscribe to them. This pattern is otherwise known as pub/sub, as publishers and subscribers are completely decoupled.
1919

2020
<aside data-type='note'>
21-
<p>Messages are counted in 2KiB chunks. See "what counts as a message":https://faqs.ably.com/how-does-ably-count-messages. </p>
21+
<p>Messages are counted in 5KiB chunks. See "what counts as a message":https://faqs.ably.com/how-does-ably-count-messages. </p>
2222
</aside>
2323

2424
h2(#properties). Message properties
@@ -31,7 +31,7 @@ The following are the properties of a message:
3131
- clientId := The "ID of the client":/auth/identified-clients that published the message.
3232
- connectionId := The ID of the connection used to publish the message.
3333
- timestamp := The timestamp of when the message was received by Ably, as milliseconds since the Unix epoch.
34-
- extras := A JSON object of arbitrary key-value pairs that may contain metadata, and/or ancillary payloads. Valid payloads include those related to "Push Notifications":/push, "deltas":/channels/options/deltas and and headers.
34+
- extras := A JSON object of arbitrary key-value pairs that may contain metadata, and/or ancillary payloads. Valid payloads include those related to "Push Notifications":/push, "deltas":/channels/options/deltas and headers.
3535
- encoding := This is typically empty, as all messages received from Ably are automatically decoded client-side using this value. However, if the message encoding cannot be processed, this attribute contains the remaining transformations not applied to the data payload.
3636

3737
h2(#conflation). Message conflation
@@ -70,3 +70,54 @@ Use the following steps to configure message conflation for a channel, or channe
7070
<aside data-type='note'>
7171
<p>Message conflation is mutually exclusive with "server-side batching":/messages/batch#server-side on a channel, or channel namespace.</p>
7272
</aside>
73+
74+
h2(#routing). Message routing and conflation syntax
75+
76+
Ably uses common syntax to select which messages are routed to integrations and for assessing which messages to apply conflation to. The following properties and features use this syntax:
77+
78+
* @routingKey@ for "AMQP":/general/firehose/amqp-rule and "Kafka":/general/firehose/kafka-rule integrations
79+
* @partitionKey@ for "AWS Kinesis":/general/firehose/kinesis-rule integrations
80+
* @conflationKey@ for "message conflation":#conflation
81+
82+
h3(#interpolation). Interpolation
83+
84+
As part of the syntax, interpolation is available to use the properties of a message to create the routing or conflation key.
85+
86+
The following properties can be used as variables:
87+
88+
- @channelName@ := The name of a channel.
89+
- @message.name@ := The name of the message.
90+
- @message.id@ := The unique ID of the message.
91+
- @message.clientId@ := The ID of the client that published the message.
92+
- @message.extras.headers['<header-name>']@ := The value of the specified header in the @message.extras@ field.
93+
94+
Interpolation uses the @#{...}@ syntax, for example @channel-name-identifier-#{channel-1}@.
95+
96+
<aside data-type='note'>
97+
<p>For a Kafka rule, the @routingKey@ includes both the topic and message routing key joined by a colon, for example @topic:key@, or with interpolation @topic-#{channelName}:message-key-#{message.name}@. So either, or both, can be dynamic. This split is done after any interpolation, but since Kafka topics cannot contain a colon, this does not introduce any ambiguity.</p>
98+
</aside>
99+
100+
h3(#filters). Filters
101+
102+
Interpolation can optionally be followed by a filter using pipe syntax.
103+
104+
The following filters are supported:
105+
106+
- hash := Transforms the variable into a stringified 32-bit fingerprint. It takes an optional numerical argument, the base to use when stringifying, which defaults to 16.
107+
- moduloHash := Similar to hash, but runs the result through a modulo function before stringifying. This is useful for bucketing. It takes one mandatory argument; the number of buckets, and one optional argument; the base to use when stringifying, which defaults to 16.
108+
109+
If using a filter, you can specify a tuple of two or more variables as the input to the filter. It should be comma-separated and delimited with parentheses.
110+
111+
h3(#examples). Routing and conflation syntax examples
112+
113+
The following are examples of using interpolation and filters to create a routing or conflation key:
114+
115+
* Hashed channel name as hex: @#{channelName | hash}@
116+
* Hashed channel name as decimal: @#{channelName | hash(10)}@
117+
* @the-foo-header-is-#{ message.extras.headers['foo'] }@
118+
* Channel name in mod 256: @#{channelName | moduloHash(256)}@
119+
* Channel name in octal: @#{channelName | moduloHash(256, 8)}@
120+
* @message name: #{message.name}, clientId: #{message.clientId}@
121+
* Hexadecimal hash combining all message properties except id: @#{(message.name, message.clientId, channelName) | hash}@
122+
* @#{message.id}@ will be different for every message, so useful for routing to kinesis shards at random
123+
* @shard-#{message.id | moduloHash(4, 10)}@ will be one of "shard-0", "shard-1", "shard-2", "shard-3"

0 commit comments

Comments
 (0)