In the following example we choose a pre-existing CKafka topic with name ckafka_trigger
. The function will be called every time a message is sent to the test
topic.
functions:
hello_world:
handler: index.main_handler
runtime: Nodejs8.9
events:
- ckafka:
name: ckafka_trigger
parameters:
name: ckafka-2o10hua5 # ckafka-id
topic: test
maxMsgNum: 999
offset: latest
enable: true
Note: CKafka triggers are enabled by default, and the consumer of CKafka will start to get the message from the latest
offset.
When the specified CKafka topic receives a message, the backend consumer module of SCF will consume the message and encapsulate the message into an event in JSON format like the one below, which triggers the bound function and pass the data content as input parameters to the function.
{
"Records": [
{
"Ckafka": {
"topic": "test-topic",
"partition": 1,
"offset": 36,
"msgKey": "None",
"msgBody": "Hello from Ckafka!"
}
},
{
"Ckafka": {
"topic": "test-topic",
"partition": 1,
"offset": 37,
"msgKey": "None",
"msgBody": "Hello from Ckafka again!"
}
}
]
}
Product