Rules engine can forward processed data from IoT Platform to Function Compute (FC).
- On the Function Compute console, create a service and function.
- Create a rule to send data processed on IoT Platform to FC, and then enable the rule.
- Send a message to the topic that has rules engine configured.
- View the function execution statistics on the Function Compute console, or check whether the configuration result is correct based on specific business logic of the function.
You can use the new version or old version of the data forwarding feature to forward data to Function Compute. For more information about how to use the new version of the data forwarding feature, see Use the new version of the data forwarding feature to forward data to Function Compute.
- Log on to the Function Compute console. Create a service and function.
- Create a service. Service Name is required. Configure other parameters as required.
- After you have created a service, create a function.
- Select a function template. A blank template is used as an example.
- Set parameters for the function.
The function is configured to directly display data on the Function Compute console.
In the proceeding parameters,
Service Name: Select the Function Compute service.
Function Name: Specify the name of your function.
Runtime: Configure the running environment for the function, for example, java8.
Code Configuration: Upload your code.
Function Handler: Configure the function entry called to run FC. Set it to com.aliyun.fc.FcDemo::handleRequest.
Configure other parameters as required. For more information, see configurations in Function Compute.
- Verify whether the function runs as intended.
After you create a function, you can run it on the Function Compute console for verification. FC will display information about function output and requests on the Function Compute console.
- Configure rules engine after the function successfully passes the verification.
- Before you configure rules engine, follow the instructions in Configure a data forwarding rule to write a SQL script to process the data.Note Data in JSON and binary formats can be forwarded to FC.
- Click Add Operation.
- On the Add Operation page, configure parameters:
- Select Operation: Select Function Compute.
- Region: Select the region that your need to forward data based on your business requirements. If the region does not have any relevant resources, go to Function Compute Console to create resources.Note Data forwarding to FC is supported in regions including China (Shanghai), Singapore, and Japan (Tokyo).
- Service: Select a service based on your region. If there are no services available, click Create Service.
- Function: Select a function based on your region. If there are no functions available, click Create Function.
- Authorization: Specify the role granted IoT Platform the permission to operate functions. You need to create a role with permissions to operate functions before you assign the role to rules engine.
- Enable the rule. After you run the rule, IoT Platform sends the processed data to FC based on the compiled SQL statements. The Function Compute console directly displays the received data based on the defined function logic.
Verify the forwarding result
The Function Compute console collects monitored statistics about function execution. Statistics are delayed for five minutes, after which you can view monitored statistics about function execution on the dashboard.