Singleton Azure function running as separate instances












1















We have an Azure function that is supposed to be handling several service bus triggers at the same time and what I assume is happening is that it is being split across several instances which is causing some concurrency problems on our end.



We need our function to act as a singleton so we can process requests one at a time without any collisions. From what we looked into in this article (https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#singleton-attribute) we should be able to accomplish this.



Our function looks like this:



[Microsoft.Azure.WebJobs.Singleton(Mode = SingletonMode.Listener)]
[FunctionName("AccountCreatedSubscriber")]
public static void Run([ServiceBusTrigger("accountscontacts-account-created", "license-keys", Connection = "FBISEventBus")]BrokeredMessage message, ILogger log)
{
log.LogInformation($"{{ Message received from accountscontacts-account-created topic }}");

// Do Work
log.LogInformation($"{{ Message sent to account creation handler }}");
}


And for backup we also have this in our host.json file,



{
"serviceBus": { "maxConcurrentCalls": 1 }
}


But for whatever reason our functions are still running parallel. Any ideas?










share|improve this question





























    1















    We have an Azure function that is supposed to be handling several service bus triggers at the same time and what I assume is happening is that it is being split across several instances which is causing some concurrency problems on our end.



    We need our function to act as a singleton so we can process requests one at a time without any collisions. From what we looked into in this article (https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#singleton-attribute) we should be able to accomplish this.



    Our function looks like this:



    [Microsoft.Azure.WebJobs.Singleton(Mode = SingletonMode.Listener)]
    [FunctionName("AccountCreatedSubscriber")]
    public static void Run([ServiceBusTrigger("accountscontacts-account-created", "license-keys", Connection = "FBISEventBus")]BrokeredMessage message, ILogger log)
    {
    log.LogInformation($"{{ Message received from accountscontacts-account-created topic }}");

    // Do Work
    log.LogInformation($"{{ Message sent to account creation handler }}");
    }


    And for backup we also have this in our host.json file,



    {
    "serviceBus": { "maxConcurrentCalls": 1 }
    }


    But for whatever reason our functions are still running parallel. Any ideas?










    share|improve this question



























      1












      1








      1








      We have an Azure function that is supposed to be handling several service bus triggers at the same time and what I assume is happening is that it is being split across several instances which is causing some concurrency problems on our end.



      We need our function to act as a singleton so we can process requests one at a time without any collisions. From what we looked into in this article (https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#singleton-attribute) we should be able to accomplish this.



      Our function looks like this:



      [Microsoft.Azure.WebJobs.Singleton(Mode = SingletonMode.Listener)]
      [FunctionName("AccountCreatedSubscriber")]
      public static void Run([ServiceBusTrigger("accountscontacts-account-created", "license-keys", Connection = "FBISEventBus")]BrokeredMessage message, ILogger log)
      {
      log.LogInformation($"{{ Message received from accountscontacts-account-created topic }}");

      // Do Work
      log.LogInformation($"{{ Message sent to account creation handler }}");
      }


      And for backup we also have this in our host.json file,



      {
      "serviceBus": { "maxConcurrentCalls": 1 }
      }


      But for whatever reason our functions are still running parallel. Any ideas?










      share|improve this question
















      We have an Azure function that is supposed to be handling several service bus triggers at the same time and what I assume is happening is that it is being split across several instances which is causing some concurrency problems on our end.



      We need our function to act as a singleton so we can process requests one at a time without any collisions. From what we looked into in this article (https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-how-to#singleton-attribute) we should be able to accomplish this.



      Our function looks like this:



      [Microsoft.Azure.WebJobs.Singleton(Mode = SingletonMode.Listener)]
      [FunctionName("AccountCreatedSubscriber")]
      public static void Run([ServiceBusTrigger("accountscontacts-account-created", "license-keys", Connection = "FBISEventBus")]BrokeredMessage message, ILogger log)
      {
      log.LogInformation($"{{ Message received from accountscontacts-account-created topic }}");

      // Do Work
      log.LogInformation($"{{ Message sent to account creation handler }}");
      }


      And for backup we also have this in our host.json file,



      {
      "serviceBus": { "maxConcurrentCalls": 1 }
      }


      But for whatever reason our functions are still running parallel. Any ideas?







      c# azure concurrency azure-functions






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 2 at 6:29









      marc_s

      580k13011181266




      580k13011181266










      asked Jan 2 at 4:20









      tokyo0709tokyo0709

      6632920




      6632920
























          1 Answer
          1






          active

          oldest

          votes


















          2















          1. If your function is on Consumption plan, set WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT to 1 in Application settings.



          2. Check your Azure Function runtime version in portal(Platform features> Function app settings). If it's ~2, we need to modify service bus setting in host.json as below.



            {
            "version": "2.0",
            "extensions": {
            "serviceBus": {
            "messageHandlerOptions": {
            "maxConcurrentCalls": 1
            }
            }
            }
            }







          share|improve this answer


























          • Sorry, we had tried this at first and I thought it didn't do anything for us but it was a different issue I realized and this did seem to help with some of the concurrency we were dealing with thank you.

            – tokyo0709
            Jan 8 at 3:59











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001149%2fsingleton-azure-function-running-as-separate-instances%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2















          1. If your function is on Consumption plan, set WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT to 1 in Application settings.



          2. Check your Azure Function runtime version in portal(Platform features> Function app settings). If it's ~2, we need to modify service bus setting in host.json as below.



            {
            "version": "2.0",
            "extensions": {
            "serviceBus": {
            "messageHandlerOptions": {
            "maxConcurrentCalls": 1
            }
            }
            }
            }







          share|improve this answer


























          • Sorry, we had tried this at first and I thought it didn't do anything for us but it was a different issue I realized and this did seem to help with some of the concurrency we were dealing with thank you.

            – tokyo0709
            Jan 8 at 3:59
















          2















          1. If your function is on Consumption plan, set WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT to 1 in Application settings.



          2. Check your Azure Function runtime version in portal(Platform features> Function app settings). If it's ~2, we need to modify service bus setting in host.json as below.



            {
            "version": "2.0",
            "extensions": {
            "serviceBus": {
            "messageHandlerOptions": {
            "maxConcurrentCalls": 1
            }
            }
            }
            }







          share|improve this answer


























          • Sorry, we had tried this at first and I thought it didn't do anything for us but it was a different issue I realized and this did seem to help with some of the concurrency we were dealing with thank you.

            – tokyo0709
            Jan 8 at 3:59














          2












          2








          2








          1. If your function is on Consumption plan, set WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT to 1 in Application settings.



          2. Check your Azure Function runtime version in portal(Platform features> Function app settings). If it's ~2, we need to modify service bus setting in host.json as below.



            {
            "version": "2.0",
            "extensions": {
            "serviceBus": {
            "messageHandlerOptions": {
            "maxConcurrentCalls": 1
            }
            }
            }
            }







          share|improve this answer
















          1. If your function is on Consumption plan, set WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT to 1 in Application settings.



          2. Check your Azure Function runtime version in portal(Platform features> Function app settings). If it's ~2, we need to modify service bus setting in host.json as below.



            {
            "version": "2.0",
            "extensions": {
            "serviceBus": {
            "messageHandlerOptions": {
            "maxConcurrentCalls": 1
            }
            }
            }
            }








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 2 at 8:25

























          answered Jan 2 at 5:23









          Jerry LiuJerry Liu

          11.3k11232




          11.3k11232













          • Sorry, we had tried this at first and I thought it didn't do anything for us but it was a different issue I realized and this did seem to help with some of the concurrency we were dealing with thank you.

            – tokyo0709
            Jan 8 at 3:59



















          • Sorry, we had tried this at first and I thought it didn't do anything for us but it was a different issue I realized and this did seem to help with some of the concurrency we were dealing with thank you.

            – tokyo0709
            Jan 8 at 3:59

















          Sorry, we had tried this at first and I thought it didn't do anything for us but it was a different issue I realized and this did seem to help with some of the concurrency we were dealing with thank you.

          – tokyo0709
          Jan 8 at 3:59





          Sorry, we had tried this at first and I thought it didn't do anything for us but it was a different issue I realized and this did seem to help with some of the concurrency we were dealing with thank you.

          – tokyo0709
          Jan 8 at 3:59




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54001149%2fsingleton-azure-function-running-as-separate-instances%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas