We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
kafkaPublishTimestamp
1 parent ce17c69 commit 173aa5bCopy full SHA for 173aa5b
broker/setup_broker/lvk/templates/ps_lvk_add_top_level_fields_smt.yaml
@@ -0,0 +1,18 @@
1
+# https://cloud.google.com/pubsub/docs/smts/create-topic-smt#create
2
+- javascriptUdf:
3
+ code: >
4
+ function addTopLevelFields(message, metadata) {
5
+ const data = JSON.parse(message.data);
6
+ const attrs = message.attributes || {};
7
+
8
+ const payload = {
9
+ ...data, // spread the original JSON fields into the root
10
+ kafkaPublishTimestamp: attrs["kafka.timestamp"] ? Number(attrs["kafka.timestamp"]) * 1000 : null
11
+ };
12
13
+ return {
14
+ data: JSON.stringify(payload),
15
+ attributes: attrs // preserve attributes
16
17
+ }
18
+ functionName: addTopLevelFields
0 commit comments