Push events from SMQ to Function Compute
This topic describes how to use EventBridge to push events from Simple Message Queue (formerly MNS) (SMQ) to Function Compute.
Before you start
Make sure that the following operations are performed:
EventBridge
Function Compute
SMQ
Step 1: Create a custom event source
Log on to the EventBridge console.
In the left-side navigation pane, click Event Buses.
In the top navigation bar, select a region.
On the Event Buses page, click the name of the custom event bus that you created.
In the left-side navigation pane, click Event Sources.
On the Event Source page, click Add Event Source.
In the Add Custom Event Source panel, configure the Name and Description parameters, select SMQ from the Event Provider drop-down list, select a created queue from the Queue Name drop-down list, and then click OK.
Step 2: Create an event rule
The target service and the event rule must be in the same region.
- Log on to the EventBridge console. In the left navigation pane, click Event Buses.
- In the top navigation bar, select a region. On the Event Buses page, click the target event bus.
- In the left navigation pane, click Event Rules, and then click Create Rule.
-
On the Create Rule page, complete the following steps.
-
In the Configure Basic Info wizard, enter a name for the rule in the Name text box and a description in the Description text box, and then click Next.
-
In the Configure Event Pattern step, set Event Source Type to Custom Event Sources. For Event Sources, select the custom event source created in Step 1. Enter an event pattern in the Pattern Content editor, and then click Next.
For more information, see Event patterns.
-
In the Configure Targets step, configure the event target, and then click Create.
NoteAn event rule can have up to five targets.
Parameter
Description
Service Type
Select Function Compute from the drop-down list.
Function
Select the function that you created.
Event
The supported transformation types are Complete Event, Partial Event, Fixed Value, and Template. This topic uses the Template type as an example. For more information, see event transformation.
The following provides examples of Variables and Template.
Variables:
{ "source":"$.source", "type":"$.type" }Template:
The event comes from ${source},event type is ${type}.Version/Alias
You can target a specific function version or alias.
-
If you select Specified Version, you must select a specific function version.
-
If you select Specified Alias, you must select a specific function alias.
Invocation Mode
Two invocation methods are supported. For more information, see Synchronous invocation and Asynchronous invocation overview.
-
Synchronous: The function processes the event and returns a result immediately.
-
Asynchronous: Function Compute receives and queues the request, then returns a response immediately.
Delivery Method
Two event formats are supported:
-
Object: If you select this format, the event is delivered to the downstream function as an object.
-
ObjectList: If you select this format, the event is delivered to the downstream function as an array of objects.
NoteIf you omit this parameter, events are delivered in Object format by default.
Retry Policy and Dead-letter Queue
For setup instructions, see Retry policy and dead-letter queue.
-
-
Step 3: Publish an event
Log on to the SMQ console.
In the left-side navigation pane, choose Queue Model > Queues.
In the top navigation bar, select a region.
On the Queues page, find the queue that you want to manage and choose in the Action column.
In the Send Message section of the Quick Experience page, configure the Message Content and Message Delay Period parameters, and then click Send Message.
The "The message is sent" message appears on the page.
Verify the results
You can verify that the function was invoked by checking its logs in the Function Compute console.
-
Log on to the Function Compute console.
-
In the left navigation pane, click Function. In the top navigation bar, select the target region.
-
On the Function page, click the name of the target function.
-
On the Function Details page, click the Log tab, and then click Function Logs to view the logs for the target function.
FAQ
How can I locate the issue if the event fails to be published?
If an event fails to be published, you can view the response to the publishing request for troubleshooting. You can go to the EventBridge console and view the related information in the Event Delivery section of the Event Trace message. Then, take appropriate measures based on the response returned.
What can I do if an event fails to be published to Function Compute and the "[500]ConnectErrorconnectiontimedout" error is returned in the response?
You can perform the following steps:
Log on to the Function Compute console. Execute the function to which the event is routed and check the execution duration.
If the execution duration is longer than 15s, check the network connection. If the execution duration is shorter than 15s, check whether you can access the endpoint for the region where the service to which the event is routed is deployed.
If you cannot access the endpoints of the region where Function Compute is deployed, contact the What is Function Compute.