%3CLINGO-SUB%20id%3D%22lingo-sub-2079995%22%20slang%3D%22en-US%22%3EAzure%20Logic%20Apps%20Running%20Anywhere%20-%20Built-In%20Service%20Bus%20Trigger%3A%20batching%20and%20session%20handling%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2079995%22%20slang%3D%22en-US%22%3E%3CP%20class%3D%22lia-align-center%22%3E%3CSTRONG%3EBuilt-In%20Service%20Bus%20Trigger%3A%20batched%20message%20processing%20and%20session%20handling%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ELogic%20App%20Refresh%20preview%20provides%20us%20with%20the%20option%20to%20create%20a%20built-in%20Service%20Bus%20trigger%20to%20receive%20messages%20from%20Service%20Bus%20topic%20or%20queue.%3C%2FP%3E%0A%3CP%3EIn%20this%20blog%20post%20two%20advanced%20Service%20Bus%20message%20processing%20are%20discussed%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EAzure%20Service%20Bus%20batch%20processing%20and%20how%20to%20configure%20the%20max%20batch%20count%20of%20messages.%3C%2FLI%3E%0A%3CLI%3EMessages%20processing%20in%20Logic%20App%20for%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-bus-messaging%2Fmessage-sessions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Esession-aware%3C%2FA%3E%20Service%20Bus%20queues%20or%20subscriptions.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3EService%20Bus%20queue%20batch%20processing%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ETo%20improve%20the%20message%20retrieval%20performance%20for%20Service%20Bus%20queue%2C%20it%20is%20highly%20recommended%20to%20receive%20the%20messages%20in%20batch.%20The%20Logic%20App%20Service%20Bus%20trigger%20for%20queue%20by%20default%20supports%20array%20of%20Service%20Bus%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fmicrosoft.azure.servicebus.message%3Fview%3Dazure-dotnet%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Emessages%3C%2FA%3E%20as%20output.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22praveensri_1-1611173868479.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F247823i95853D1812D286CA%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22praveensri_1-1611173868479.png%22%20alt%3D%22praveensri_1-1611173868479.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-bus-messaging%2Fservice-bus-performance-improvements%3Ftabs%3Dnet-standard-sdk-2%23prefetching%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EprefetchCount%26nbsp%3B%3C%2FA%3Eis%20used%20to%20specify%20how%20many%20messages%20should%20be%20retrieved%20in%20a%20%22batch%22%20to%20save%20the%20roundtrips%20from%20Logic%20Apps%20back%20to%20the%20Azure%20Service%20Bus.%20Prefetching%20messages%20increases%20the%20overall%20throughput%20for%20a%20queue%20by%20reducing%20the%20overall%20number%20of%20message%20operations%2C%20or%20round%20trips.%3C%2FP%3E%0A%3CP%3EThe%20prefetchCount%20can%20be%20configured%20in%20the%20global%20configuration%20settings%20in%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-bindings-service-bus-output%3Ftabs%3Dcsharp%23host-json%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehost.json%3C%2FA%3E%2C%20the%20Azure%20function%20trigger%20requests%20these%20many%20messages%20for%20the%20Azure%20Function.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%7B%0A%20%20%20%20%22version%22%3A%20%222.0%22%2C%0A%20%20%20%20%22extensions%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22serviceBus%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22prefetchCount%22%3A%2020%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%22messageHandlerOptions%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22autoComplete%22%3A%20true%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22maxConcurrentCalls%22%3A%2032%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22maxAutoRenewDuration%22%3A%20%2200%3A05%3A00%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20host.json%20can%20be%20edited%20using%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Feducator-developer-blog%2Fusing-kudu-and-deploying-apps-into-azure%2Fba-p%2F378585%22%20target%3D%22_blank%22%3EKudu%20Advance%20tool%3C%2FA%3E%20(in%20case%20the%20Logic%20App%20is%20created%20in%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Flogic-apps%2Fcreate-stateful-stateless-workflows-azure-portal%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Portal%3C%2FA%3E).%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22praveensri_2-1611173868496.png%22%20style%3D%22width%3A%20419px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F247824i13D73F23FC8F8065%2Fimage-dimensions%2F419x445%3Fv%3D1.0%22%20width%3D%22419%22%20height%3D%22445%22%20role%3D%22button%22%20title%3D%22praveensri_2-1611173868496.png%22%20alt%3D%22praveensri_2-1611173868496.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EMessage%20processing%20for%20session-aware%20service%20bus%20queue%2Fsubscriptions%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EYou%20can%20enable%20the%20session%20by%20selecting%20the%20Enable%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fservice-bus-messaging%2Fmessage-sessions%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Esessions%3C%2FA%3E%20checkbox%20while%20creating%20the%20Service%20Bus%20queue%20in%20UI%20%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22praveensri_3-1611173868501.png%22%20style%3D%22width%3A%20295px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F247825i55B9BE7C494A40F8%2Fimage-dimensions%2F295x642%3Fv%3D1.0%22%20width%3D%22295%22%20height%3D%22642%22%20role%3D%22button%22%20title%3D%22praveensri_3-1611173868501.png%22%20alt%3D%22praveensri_3-1611173868501.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20session-aware%20Service%20Bus%20queue%20the%20built-in%20Service%20Bus%20trigger%20cannot%20receive%20the%20message%20by%20default.%20The%20sessions%20are%20not%20enabled%20for%20Service%20Bus%20trigger%20by%20default.%3C%2FP%3E%0A%3CP%3EThe%20Azure%20Service%20Bus%20trigger%20is%20based%20upon%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-bindings-service-bus-trigger%3Ftabs%3Dcsharp%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EAzure%20Function%20ServiceBusTrigger%3C%2FA%3E%20binding%20configuration%20of%20Azure%20function%2C%20the%20isSessionsEnabled%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-functions%2Ffunctions-bindings-service-bus-trigger%3Ftabs%3Dcsharp%23configuration%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Econfiguration%3C%2FA%3E%20needs%20to%20set%20for%20it%20to%20enable%20the%20session%20processing.%20This%20option%20can%20be%20handled%20in%20the%20logic%20app%20code%20definition%20as%20given%20below%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-json%22%3E%3CCODE%3E%20%20%20%20%20%20%20%20%22triggers%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%22When_messages_are_available_in_Service_Bus_queue%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22inputs%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22parameters%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22isSessionsEnabled%22%3A%20true%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22queueName%22%3A%20%22psrivassbq5%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20you%20update%20the%20Logic%20App%20definition%20you%20can%20view%20this%20in%20the%20designer%20as%20shown%20below.%20However%2C%20the%20isSessionsEnabled%20trigger%20input%20option%20cannot%20be%20configured%20on%20the%20designer%20surface.%20The%20input%20option%20IsSessionEnabled%20in%20UI%20will%20be%20provided%20in%20the%20Logic%20App%20Refresh%20future%20release.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22praveensri_4-1611173868505.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F247826i9EC39245B97BB513%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22praveensri_4-1611173868505.png%22%20alt%3D%22praveensri_4-1611173868505.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhen%20the%20messages%20are%20queued%20in%20Service%20Bus%20session%20queue%2C%20it%20will%20trigger%20the%20Service%20Bus%20trigger%20based%20upon%20sessions%20in%20Service%20Bus%20queue.%20You%20can%20use%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fdotnet%2Fapi%2Fmicrosoft.servicebus.messaging.messagesession.sessionid%3Fview%3Dazure-dotnet%23Microsoft_ServiceBus_Messaging_MessageSession_SessionId%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESessionId%3C%2FA%3E%20%26nbsp%3Bproperty%20from%20Service%20Bus%20trigger%20output.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22praveensri_5-1611173868510.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F247827i6BC31695298A7A71%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22praveensri_5-1611173868510.png%22%20alt%3D%22praveensri_5-1611173868510.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2079995%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22praveensri_0-1611173665919.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F247822i6258E50FDCA56067%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22praveensri_0-1611173665919.png%22%20alt%3D%22praveensri_0-1611173665919.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ELogic%20App%20Refresh%20preview%20provides%20us%20with%20the%20option%20to%20create%20a%20built-in%20Service%20Bus%20trigger%20to%20receive%20messages%20from%20Service%20Bus%20queue.%3C%2FP%3E%0A%3CP%3ETo%20improve%20the%20message%20retrieval%20performance%20for%20Service%20Bus%20queue%2C%20it%20is%20highly%20recommended%20to%20receive%20the%20messages%20in%20batch.%26nbsp%3B%3CSPAN%3EAzure%20Service%20Bus%20sessions%20enable%20joint%20and%20ordered%20handling%20of%20unbounded%20sequences%20of%20related%20messages%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2079995%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ELogic%20Apps%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Built-In Service Bus Trigger: batched message processing and session handling

Logic App Refresh preview provides us with the option to create a built-in Service Bus trigger to receive messages from Service Bus topic or queue.

In this blog post two advanced Service Bus message processing are discussed:

  • Azure Service Bus batch processing and how to configure the max batch count of messages.
  • Messages processing in Logic App for the session-aware Service Bus queues or subscriptions.

Service Bus queue batch processing:

To improve the message retrieval performance for Service Bus queue, it is highly recommended to receive the messages in batch. The Logic App Service Bus trigger for queue by default supports array of Service Bus messages as output.

praveensri_1-1611173868479.png

 

The prefetchCount is used to specify how many messages should be retrieved in a "batch" to save the roundtrips from Logic Apps back to the Azure Service Bus. Prefetching messages increases the overall throughput for a queue by reducing the overall number of message operations, or round trips.

The prefetchCount can be configured in the global configuration settings in host.json, the Azure function trigger requests these many messages for the Azure Function.

 

 

 

{
    "version": "2.0",
    "extensions": {
        "serviceBus": {
            "prefetchCount": 20,
            "messageHandlerOptions": {
                "autoComplete": true,
                "maxConcurrentCalls": 32,
                "maxAutoRenewDuration": "00:05:00"
            }

 

 

         

The host.json can be edited using Kudu Advance tool (in case the Logic App is created in Azure Portal).

praveensri_2-1611173868496.png

 

 

Message processing for session-aware service bus queue/subscriptions:

You can enable the session by selecting the Enable sessions checkbox while creating the Service Bus queue in UI :

praveensri_3-1611173868501.png

 

In the session-aware Service Bus queue the built-in Service Bus trigger cannot receive the message by default. The sessions are not enabled for Service Bus trigger by default.

The Azure Service Bus trigger is based upon Azure Function ServiceBusTrigger binding configuration of Azure function, the isSessionsEnabled configuration needs to set for it to enable the session processing. This option can be handled in the logic app code definition as given below:

 

 

 

        "triggers": {
            "When_messages_are_available_in_Service_Bus_queue": {
                "inputs": {
                    "parameters": {
                        "isSessionsEnabled": true,
                        "queueName": "psrivassbq5"
                    }

 

 

 

Once you update the Logic App definition you can view this in the designer as shown below. However, the isSessionsEnabled trigger input option cannot be configured on the designer surface. The input option IsSessionEnabled in UI will be provided in the Logic App Refresh future release.

 

praveensri_4-1611173868505.png

 

When the messages are queued in Service Bus session queue, it will trigger the Service Bus trigger based upon sessions in Service Bus queue. You can use the SessionId  property from Service Bus trigger output.

praveensri_5-1611173868510.png