locked
Logic Apps from queue RRS feed

  • Question

  • Hi All,

    I have two Logic Apps - LA1 and LA2. LA1 calls LA2 in a for-each for 5 times by passing a parameter. In LA2, I need to receive message from a queue (we can change it to topic if it helps). And check whether the received message contains the value received as parameter from LA2.

    My problem is since LA2 is called in a loop and checks a value by retrieving a message from a queue, when the logic apps run 5 times in a loop from parent logic apps-LA1, In LA2 the second or third instances of logic app is not able to share the message from the queue. I use peek-lock.

    How do I share a message from a queue when multiple instances of the logic apps reads the same message.

    Tuesday, July 11, 2017 7:15 AM

Answers

  • Hi Ganesh,

    If you change the mode of your foreach to sequential ("operationOptions": "Sequential"), you will have the LA2 called in sequence, instead in parallel.

    This way LA2 is the only one accessing the queue at that point, so you don't have to share. I'm assuming that you are using peek-lock, and if the message is not the one you're looking, you abandon, so the next loop interaction can pick up the file?

    Here is an example of a foreach with the sequential parameter setup:

    "forEach_email": {
            "type": "foreach",
            "foreach": "@body('email_filter')",
    	"operationOptions": "Sequential",
            "actions": {
                "send_email": {
                    "type": "ApiConnection",
                    "inputs": {
                    "body": {
                        "to": "@item()",
                        "from": "me@contoso.com",
                        "message": "Hello, thank you for ordering"
                    },
                    "host": {
                        "connection": {
                            "id": "@parameters('$connections')['office365']['connection']['id']"
                        }
                    },
                    }
                }
            },
            "runAfter":{
                "email_filter": [ "Succeeded" ]
            }
        }
    
    I hope this helps, Wagner.

    • Marked as answer by AlastairAndy Wednesday, July 12, 2017 11:50 AM
    Tuesday, July 11, 2017 8:53 AM

All replies

  • Hi Ganesh,

    If you change the mode of your foreach to sequential ("operationOptions": "Sequential"), you will have the LA2 called in sequence, instead in parallel.

    This way LA2 is the only one accessing the queue at that point, so you don't have to share. I'm assuming that you are using peek-lock, and if the message is not the one you're looking, you abandon, so the next loop interaction can pick up the file?

    Here is an example of a foreach with the sequential parameter setup:

    "forEach_email": {
            "type": "foreach",
            "foreach": "@body('email_filter')",
    	"operationOptions": "Sequential",
            "actions": {
                "send_email": {
                    "type": "ApiConnection",
                    "inputs": {
                    "body": {
                        "to": "@item()",
                        "from": "me@contoso.com",
                        "message": "Hello, thank you for ordering"
                    },
                    "host": {
                        "connection": {
                            "id": "@parameters('$connections')['office365']['connection']['id']"
                        }
                    },
                    }
                }
            },
            "runAfter":{
                "email_filter": [ "Succeeded" ]
            }
        }
    
    I hope this helps, Wagner.

    • Marked as answer by AlastairAndy Wednesday, July 12, 2017 11:50 AM
    Tuesday, July 11, 2017 8:53 AM
  • Hi Ganesh,

    Is there any particular reason that you want to read queue in LA2 multiple times? if not you can read queue message in LA1, compare values from queue message with the parameter and call LA2 for further actions.

    Leelavinoth P.


    Leelavinoth P.

    Tuesday, July 11, 2017 10:10 PM
  • Hi Leelavinoth,

    In both cases, you would still have to use Sequential, though, right? Because independent from where you are doing the call to the queue, parallel action means that you will be taking the first n messages from the queue, where n is the number of active parallel action.

    Based on that, having the second logic app as something that just deal with the queue logic makes sense to me.

    My two cents, Wagner.

    Wednesday, July 12, 2017 4:13 AM
  • Hi Wagner,

    There is a little misunderstanding here, LA1 will read the message only once and pass that message to LA2 as a parameter(no queue/topic read required in LA2), so it doesn't matter where the for each is sequential or parallel as all the call uses the same message.

    Apologies if I am still wrong.


    Leelavinoth P.

    Wednesday, July 12, 2017 4:34 AM
  • @Wagner:  Yes, I agree Sequentially process the message off from the queue will work and just trying it and come back. Thanks.  But I am not understood the concept of abandon and also I am not using it as you mentioned. Are there any URL reference where I can read about Service Bus actions like read, abandon, complete etc please?

    @Leelavinoth: I have two different queues, one for LA1 and another one for LA2 for different reasons. For the values I received from the message in queue1 for LA1 and loop through and check the content in the message in LA2 by passing in the parameter.

    Wednesday, July 12, 2017 5:42 AM
  • Abandon In Service Bus Enables to unlock the message and make it available to be received again, either by the same consumer or by another competing consumer.

    Complete in Service Bus Means the Message is Completed and we cannot Consume it again.

    For More Understanding on these Service Bus Methods. Please use the below Link

    https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-queues-topics-subscriptions

    https://docs.microsoft.com/en-us/connectors/servicebus/


    Sujith

    Wednesday, July 12, 2017 6:04 AM
  • Any guidelines on when do I need to use which action? i.e. if I use peek-lock, when to use abandon/complete. same with deferred.

    Also I understand what is PEEK-LOCK, but what is get deferred message from queue, is it read and delete?

    Wednesday, July 12, 2017 6:44 AM
  • Hi,

    As Far as My Knowledge goes,

     Once you Receive the Message and you don't want others to Consume this Message again you can Use Complete. (In your case if you find that this is the Message you are Looking For According to you Criteria)

    Once you Receive the message and You Found that this is not the Message you are Looking for in that Iteration, Then you can abandon the Message so that it is available and it can be Consumed again.

    Defer is something Like You will intentionally put this message aside for processing later. I don't think You can Retrieve it again Like you do it in Abandon. We must use the Sequence Number to Retrieve it.

    Others can correct me if I am wrong.


    Sujith

    Wednesday, July 12, 2017 7:05 AM
  • Hi guys,

    Sujith is spot on all point.

    In summary, when using Peek-lock:

    • if you completed the processing of the message successfuly, you use the complete action to remove it from the queue permanently

    If you didn't process your message successfully you have two options:

    • Abandon - in this case you still another process to pick up that message (exactly your case).
    • Dead Letter - you move the message to the dead letter queue because you can't process it successfully, but it is not supposed to be processed by any process. If you leave it in the queue it will hold the processing of other messages, but you might want to some manual process (fix data errors for exemplo) and resubmit or notify that the message was not processed. You can do this by having a process managing the dead letter queue.

    Defer can be used in a couple of scenarios:

    • If you need more time than the original lease time to process your message (for example you send the message to a process that might take 1 minute to respond).
    • I've also used it before when I want to pass that message to a sub process. So I can defer on the main process, pass the token to the sub process, pick it from there and continue processing.

    I hope this helps, Wagner.


    Wednesday, July 12, 2017 11:34 AM
  • Hi Leelavinoth,

    What I meant by still need to be sequential is that:

    If you are reading the queue on LA1 where you have the foreach (assuming that the read is inside the for each, since you need to compare with the foreach parameter), you would have up to 20 instances of a "get message from the queue" action running in parallel - since foreach run internal activieis in parallel  by default - which seems Alastair current problem. So you would need to make the foreach loop sequential.

    Assuming that this is the case, I prefer to keep all the queue "management" logic in a single place - especially since he is using peek-lock, which will require at least two actions and some form of decision (peek-lock, complete / abandon).

    I hope that makes sense.

    Cheers, Wagner.

    P.s.: No need to apologise mate, having a good, friendly argument is what make forums awesome! ;-D


    Wednesday, July 12, 2017 11:43 AM