Scenario: Sending Queue Messages to a Function
Integrate Queue with Functions using Connector Hub.
This scenario involves creating a function and then referencing that function as a target in a connector (Connector Hub) to receive and process messages from queues.
The payload received by the function contains only messages from the queue.
For a related tutorial, see Use OCI Functions and OCI Queue to Authorize User Capabilities without Exposing Admin Privilege to Approvers.
For help with troubleshooting, see Troubleshooting Connectors.
Required IAM Policy
If you're a member of the Administrators group, you already have the required access to execute this scenario. Otherwise, you need access to Functions.
The workflow for creating the connector includes a default policy when needed to provide permission for writing to the target service. If you're new to policies, see Getting Started with Policies and Common Policies.
Error Handling When Processing Queues
In the context of queue messages sent to functions, partial failures during processing of messages within a batch aren't supported.
When a function that's processing a batch of messages from a queue encounters an error, all messages in that batch become visible in the queue again, including messages that the function processed successfully. Therefore, a message could be processed by the function several times. As with any target, the connector keeps retrying indefinitely until the function target succeeds. For more information, see Delivery Details.
If a failure occurs while processing a batch of messages, the delivery count for those messages is still increased. If the delivery count for a message reaches the maximum defined at the queue level, then the message is sent to the dead letter queue. For more information, see Delivery count.
To prevent reprocessing of messages, make your function idempotent.
Setting Up the Queue and Function
Before you can create the connector (Connector Hub) , you must set up a queue and a function to receive data from the queue.
For queue instructions, see Creating a Queue.
For function instructions, see the following:
The creation process begins, and its progress is displayed. On completion, the connector's details page opens. Run the CreateServiceConnector operation to create the connector.
Example request:
POST /20200909/serviceConnectors Host: service-connector-hub.us-phoenix-1.oraclecloud.com <authorization and other headers> { "displayName": "My Queue to Function Connector", "compartmentId": "<compartment_OCID>", "description": "My connector description", "source": { "kind": "plugin", "pluginName": "QueueSource", "configMap": { "queueId": "<queue_OCID>" } }, "target": { "kind": "functions", "functionId": "<function_OCID>", "batchSizeInKbs": "5000", "batchSizeInNum": "10", "batchTimeInSec": "60" } }
Verify and Troubleshoot Invokes
To verify and troubleshoot invokes on the Functions service, see Storing and Viewing Function Logs.
Confirm That the New Connector Moves Data
After you create the connector, confirm that it's moving data.
- Enable logs for the connector to get details on data flow.
- Check for expected results at the target service.
Confirming that data is moved helps you avoid automatic deactivation, which happens when a connector fails for a long time.