This topic describes how to create a Function Compute sink connector to synchronize data from a source topic in your ApsaraMQ for Kafka instance to a function in Function Compute.
Prerequisites
For information about the prerequisites, see Prerequisites.Usage notes
- You must select event functions as the type of the destination function.
- If you deliver messages from Message Queue for Apache Kafka to Function Compute that resides in the same region, the data is transmitted over the internal network. In this case, you are not charged the Internet traffic fee.
Step 1: Create Function Compute resources
Create a function in Function Compute. For more information, see Create a function in the Function Compute console.
In this example, an event function named sink-fc is created for the guide-fc-sink-service service that runs in the Python runtime environment. Function code:
# -*- coding: utf-8 -*-
import logging
import json
def handler(event, context):
logger = logging.getLogger()
evt = json.loads(event)
logger.info(evt)
return "success"
Step 2: Create and start a Function Compute sink connector
- Log on to the ApsaraMQ for Kafka console. In the Resource Distribution section of the Overview page, click the name of the region where your instance is deployed.
- In the left-side navigation pane, choose .
- On the Message Outflow page, click Create Task.
- In the Create Message Outflow Task panel, configure the parameters and click Confirm. After you perform the preceding operations, go to the Message Outflow page, find the Function Compute sink connector that you created, and then click Start in the Actions column. If the status in the Status column changes from Starting to Running, the connector is created.
Step 3: Test the Function Compute sink connector
- On the Message Outflow page, find the Function Compute sink connector that you created and click the name of the source topic in the Event Source column.
- On the Topic Details page, click Send Message.
- In the Start to Send and Consume Message panel, configure the parameters based on the following figure and click OK.
- On the Message Outflow page, find the Function Compute sink connector that you created and click the name of the destination function in the Event Target column.
- Click the Logs tab. Then, click the Requests tab to view the invocation logs.