Implementation Principles
SCF supports MQTT Message Queue trigger. The trigger is based on the MQTT Shared Subscription mechanism, which can subscribe to and consume messages according to the Topic Filter defined in your business, thereby automatically triggering the corresponding function execution. Through this mechanism, SCF can establish efficient, asynchronous communication links with IoT devices. Messages are reliably routed and distributed via the MQTT cluster, and load balancing across multiple triggers is achieved through shared subscriptions, enabling high-concurrency IoT scenarios requiring real-time response, such as vehicle status monitoring and remote smart control. Use Cases
New Energy Vehicle Battery SoC Management
The vehicle's TCU module triggers SCF via MQTT message trigger and calls different services subsequently based on the vehicle's status.
Low power warning and response: When the vehicle TCU detects the battery level is below the threshold, it publishes a status message via MQTT topic, triggering SCF to perform operations such as notifying users and navigating to a charging station.
Remote device control: SCF sends instructions to the vehicle via MQTT (such as limiting air conditioning power) to implement energy-saving control.
Real-time status synchronization: Subscribe to MQTT topic via HTML/Mini Program Page to monitor battery SoC changes in real time.
Features and Advantages
Event-driven and real-time response: SCF is automatically triggered by MQTT messages with no need for polling. Device status changes (e.g. low battery SoC) can be transmitted to the cloud as events immediately, triggering subsequent business chains.
Achieves near real-time business processing, significantly reducing delay from event occurrence to system response, excellently meeting IoT application requirements for real-timeness.
Serverless architecture, ultimate elasticity and cost optimization: SCF runs in serverless mode, automatically scaling based on MQTT message arrival frequency with no need to manage servers. Zero idle cost, auto-scaling copes easily with traffic spikes, simplifying operations.
Loose coupling integration method: MQTT Topic serves as a message bus, completely decoupling device reporting from business processing. Different business features (such as notification, navigation, energy-saving control) are handled independently by different SCFs, offering high flexibility and maintainability.
Operation Steps
Policy and Permissions
1.1 Log in to the CAM console and navigate to the [Role] menu. 1.2 Search scf_qcsRole
1.3 Click role details to view policy.
1.5 If the policy is missing, follow these steps to add a policy to the role:
1.5.1 Use the root account to log in to the Tencent Cloud console.
1.5.2 Click Access Management > Policies
1.5.4 Click Associate User/Groups/Role.
1.5.5 In the pop-up window, select Switch to Roles.
1.5.6 Search scf_qcsRole, check and confirm.
1.5.7 Page prompt: Associated successfully.
Configuring an MQTT Trigger
2. Click the function name to enter the function management page.
3. Select the Trigger management TAB, click Create trigger in the upper right corner.
4. According to business needs, fill in the required Topic Filter. Messages that meet the Topic Filter trigger execution of SCF.
5. After SCF is created, observe MQTT console > Client management. You can see the trigger subscriber list.
View client details to see the subscription expression is configured the same.
Verification
Send messages to the MQTT cluster and view the SCF function log.