Document Database Service DDS

Using DDS triggers, each time a table in the database is updated, a Functiongraph function can be triggered to perform additional work. For more information about how to use DDS triggers, see Using a DDS Trigger.

DDS example event

{
  "records": [
    {
      "event_source": "dds",
      "event_name": "insert",
      "region": "{region}",
      "event_version": "1.0",
      "dds": {
        "size_bytes": "100",
        "token": "{\"_data\": \"825D8C2F4D0000001529295A100474039A3412A64BA89041DC952357FB4446645F696400645D8C2F8E5BECCB6CF5370D6A0004\"}",
        "full_document": "{\"_id\": {\"$oid\": \"5d8c2f8e5beccb6cf5370d6a\"},\"name\": \"dds\",\"age\": {\"$numberDouble \": \"52.0\"}}",
        "ns": "{\"db\": \"functiongraph\",\"coll\": \"person\"}"
      },
      "event_source_id": "e6065860-f7b8-4cca-80bd-24ef2a3bb748"
    }
  ]
}

Parameter description

Parameter

Type

Example Value

Description

region

String

{region}

The region where the DDS instance is located

event_version

String

1.0

Event protocol version

event_source

String

dds

Source of the event

event_name

String

insert

Event name

size_bytes

Int

100

The number of bytes in the message

token

String

Reference examples

Base64 encoded data

full_document

String

Reference examples

Complete file information

ns

String

Reference examples

Column Name

event_source_id

String

e6065860-f7b8-4cca-80bd-24ef2a3bb748

Event source unique identifier

Example

package main

import (
	"encoding/json"
	"fmt"

	"github.com/opentelekomcloud-community/otc-functiongraph-go-runtime/go-runtime/events/dds"
	"github.com/opentelekomcloud-community/otc-functiongraph-go-runtime/go-runtime/go-api/context"
	"github.com/opentelekomcloud-community/otc-functiongraph-go-runtime/go-runtime/pkg/runtime"
)

// Example for Document Database Service handler
func DdsTest(payload []byte, ctx context.RuntimeContext) (interface{}, error) {
	var ddsEvent dds.DDSTriggerEvent
	err := json.Unmarshal(payload, &ddsEvent)
	if err != nil {
		fmt.Println("Unmarshal failed")
		return "invalid data", err
	}
	ctx.GetLogger().Logf("payload:%s", ddsEvent.String())
	return "ok", nil
}

func main() {
	runtime.Register(DdsTest)
}