Using a DMS Trigger

For details about the DMS event source, see Supported Event Sources.

Prerequisites

Before creating a DMS trigger, make sure you have prepared the following:

Setting an Agency

Before creating a DMS trigger, set an agency to delegate FunctionGraph to access DMS. If no agency is set, FunctionGraph will not be able to load the created message queue or the message queue will be unavailable. For details on how to create an agency, see Creating an Agency.

Since you did not specify an agency while creating the HelloWorld function, specify one first.

  1. Log in to the FunctionGraph console, and choose Functions > Function List in the navigation pane.
  2. Click the HelloWorld function.
  3. On the displayed function details page, click the Configuration tab.
  4. Set the agency to serverless-trust created in Creating an Agency. Click Save.

Creating a DMS Trigger

  1. Log in to the FunctionGraph console, and choose Functions > Function List in the navigation pane.
  2. Click the HelloWorld function.
  3. On the displayed function details page, click the Triggers tab.
  4. Click Create Trigger.
  5. Set the following parameters:

    • Trigger Type: Select Distributed Message Service (DMS).
    • Queue Name: Select a queue, for example, queue-test.
    • Consumer Group: Select a consumer group, for example, group-dms.
    • Pull Period (s): Set an interval at which the DMS trigger will poll for messages.

  6. Click OK.

Creating a Message to Trigger the Function

  1. Log in to the DMS console, and choose Queue Manager in the navigation pane.
  2. On the Queue Manager page, click queue-test.
  3. On the queue details page, click Create Message.
  4. In the Create Message dialog box, configure the message information according to Table 1.

    Table 1 Message information

    Parameter

    Description

    Message Body

    Enter {"message":"hello"}.

    Message Labels

    In this example, leave this field blank.

    Message Attributes

    In this example, leave this field blank.

    For details about the parameters required for creating a message, see Creating a Message.

  5. Click OK.
  6. On the Consumer Groups tab page, check the value of Messages Available in the same row as group-dms.

    The DMS trigger polls for messages based on the pull period set in Creating a DMS Trigger. When messages are detected, they are retrieved to trigger the function. For details about example events, see Supported Event Sources.

Viewing the Execution Result

  1. Log in to the FunctionGraph console, and choose Functions > Function List in the navigation pane.
  2. Click the HelloWorld function.
  3. On the displayed function details page, click the Logs tab to query the function running logs.
  4. Click View Context in the same row as a log to view log details.