1
votes

I have the following trigger:

"triggers": {
    "When_there_are_messages_in_a_queue": {
        "inputs": {
            "host": {
                "connection": {
                    "name": "@parameters('$connections')['azurequeues']['connectionId']"
                }
            },
            "method": "get",
            "path": "/@{encodeURIComponent('drugconsortium-positive-result')}/message_trigger"
        },
        "recurrence": {
            "frequency": "Minute",
            "interval": 1
        },
        "splitOn": "@triggerBody()?['QueueMessagesList']?['QueueMessage']",
        "type": "ApiConnection"
    }
}

then I try to get messages from queue:

    "Get_messages": {
        "inputs": {
            "host": {
                "connection": {
                    "name": "@parameters('$connections')['azurequeues']['connectionId']"
                }
            },
            "method": "get",
            "path": "/@{encodeURIComponent('drugconsortium-positive-result')}/messages",
            "queries": {
                "visibilitytimeout": "30"
            }
        },
        "runAfter": {},
        "type": "ApiConnection"
    }

and then try to send email with queue content:

"For_each_2": {
    "actions": {
        "Send_email_(V4)_3": {
            "inputs": {
                "body": {
                    "from": "[email protected]",
                    "ishtml": true,
                    "subject": "message",
                    "text": "<p>want!!!@{items('For_each_2')?['MessageText']}</p>",
                    "to": "[email protected]"
                },
                "host": {
                    "connection": {
                        "name": "@parameters('$connections')['sendgrid']['connectionId']"
                    }
                },
                "method": "post",
                "path": "/v4/mail/send"
            },
            "runAfter": {},
            "type": "ApiConnection"
        }
    },
    "foreach": "@body('Get_messages')?['QueueMessagesList']?['QueueMessage']",
    "runAfter": {
        "Get_messages": [
            "Succeeded"
        ]
    },
    "type": "Foreach"
}

After execution I see a message for the trigger:

{
  "MessageId": "83aac220-9ee5-440c-9a34-391abaa0e464",
  "InsertionTime": "Thu, 12 Mar 2020 20:21:51 GMT",
  "ExpirationTime": "Thu, 19 Mar 2020 20:21:51 GMT",
  "PopReceipt": "AgAAAAMAAAAAAAAA+JoXDKz41QE=",
  "TimeNextVisible": "Thu, 12 Mar 2020 20:23:09 GMT",
  "DequeueCount": "1",
  "MessageText": "{\"DriverId\":-1,\"DriverName\":\"John Smith\",\"DriverSSN\":\"111-11-1111\",\"CarrierName\":\"Carrier Name\",\"DER\":{\"Name\":\"Der name\",\"Email\":\"[email protected]\"}}"
}

but Get_messages has in result:

QueueMessage : []

and I don't receive any email. What is wrong?

1

1 Answers

2
votes

This is because you don't need Get_messages, check the trigger definition When there are messages in a queue, it will return the Messages type, means you already get the message.

Cause the queue is already processed by the trigger the it will be removed from the queue so you could not get it again with the action.

So after the trigger you could get the message content with the dynamic content.

enter image description here