Azure / azure-functions-servicebus-extension

Service Bus extension for Azure Functions
MIT License
65 stars 35 forks source link

ServiceBus SessionHandlerOptions.MaxAutoRenewDuration would be set to default value unexpectedly #178

Closed shaykchen closed 2 years ago

shaykchen commented 2 years ago

Issue:

SessionHandlerOptions.MaxAutoRenewDuration was defined as 3-hour in host.json file:

{
  "version": "2.0",
  "functionTimeout": "03:00:00",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "maxTelemetryItemsPerSecond": 20
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[1.*, 2.0.0)"
  },
  "extensions": {
    "serviceBus": {
      "prefetchCount": 0,
      "messageHandlerOptions": {
        "autoComplete": true,
        "maxConcurrentCalls": 1,
        "maxAutoRenewDuration": "03:00:00"
      }
    },
    "sessionHandlerOptions": {
      "autoComplete": true,
      "maxConcurrentSessions": 1,
      "maxAutoRenewDuration": "03:00:00"  //Customer defined it as 3 hours here.
    }
  }
}

But it was overwritten to default value 5-minute as follows:

ServiceBusOptions
{
  "PrefetchCount": 0,
  "MessageHandlerOptions": {
    "AutoComplete": true,
    "MaxAutoRenewDuration": "03:00:00",
    "MaxConcurrentCalls": 1
  },
  "SessionHandlerOptions": {
    "AutoComplete": true,
    "MaxAutoRenewDuration": "00:05:00",  //It was overwritten to default value 5 minutes unexpectedly.
    "MaxConcurrentSessions": 2000,
    "MessageWaitTimeout": "00:01:00"
  }
}

Repro Steps:

  1. Create Java Function App + Azure Service Bus Queue with sessions enabled
  2. Modify host.json with the below content:
{
    "version": "2.0",
    "extensions": {
        "serviceBus": {
            "prefetchCount": 0,
            "messageHandlerOptions": {
                "autoComplete": true,
                "maxConcurrentCalls": 1,
                "maxAutoRenewDuration": "03:00:00"
            }
        },
        "sessionHandlerOptions": {
                "autoComplete": true,
                "maxConcurrentSessions": 1,
                "maxAutoRenewDuration": "03:00:00"
        }
    },
    "logging": {
      "applicationInsights": {
        "samplingSettings": {
          "isEnabled": true,
          "maxTelemetryItemsPerSecond" : 20
        }
      }
    },
    "functionTimeout": "03:00:00",
    "extensionBundle": {
        "id": "Microsoft.Azure.Functions.ExtensionBundle",
        "version": "[1.*, 2.0.0)"
    }
}
  1. Define the ServiceBus trigger function as follows:
@FunctionName("myFunctionName")
    public void sendFile(
            @ServiceBusQueueTrigger(name = "msg",
                    queueName = "dl-import-myFunctionQueue",
                    connection = "ConnectionString",
                    isSessionsEnabled = true) String url,
            final ExecutionContext context) {
......
  1. More details (Kusto query and source code) could be found in CRI 280328101

Workaorund:

Seems no workaround so far.

alrod commented 2 years ago

There is a mistake in the host.json configuration - sessionHandlerOptions should be on the same level as messageHandlerOptions and inside serviceBus node. See the doc for Functions 2.x: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-service-bus?tabs=in-process%2Cfunctionsv2%2Cextensionv3&pivots=programming-language-javascript#hostjson-settings