Search code examples
azure-functionsazure-servicebus-queues

Azure Functions ServiceBusQueueTrigger NullPointerException


I have an Azure Functions method that is Service Bus Queue Trigger. Method does not have anything but a log line. It starts up fine but when receiving a message it runs in an Exception at Action=ProcessMessageCallback. I have tried to troubleshoot the bindings, adjust configs but no help.

[2022-07-05T07:32:25.312Z] System.Private.CoreLib: Exception while executing function: Functions.ScalaFunction. System.Private.CoreLib: Result: Failure
[2022-07-05T07:32:25.312Z] Exception: NullPointerException:
[2022-07-05T07:32:25.312Z] Stack: java.lang.NullPointerException
[2022-07-05T07:32:25.312Z]  at com.microsoft.azure.functions.worker.binding.BindingDataStore.getDataByName(BindingDataStore.java:62)
[2022-07-05T07:32:25.312Z]  at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:59)
[2022-07-05T07:32:25.312Z]  at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:42)
[2022-07-05T07:32:25.312Z]  at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:53)
[2022-07-05T07:32:25.312Z]  at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:62)
[2022-07-05T07:32:25.312Z]  at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:33)
[2022-07-05T07:32:25.312Z]  at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)
[2022-07-05T07:32:25.312Z]  at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45)
[2022-07-05T07:32:25.312Z]  at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92)
[2022-07-05T07:32:25.312Z]  at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[2022-07-05T07:32:25.312Z]  at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[2022-07-05T07:32:25.312Z]  at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[2022-07-05T07:32:25.312Z]  at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[2022-07-05T07:32:25.312Z]  at java.base/java.lang.Thread.run(Thread.java:834)
[2022-07-05T07:32:25.312Z] .
[2022-07-05T07:32:25.358Z] Message processing error (Action=ProcessMessageCallback, EntityPath=<queueName>, Endpoint=<endpoint>)

host.json

{
  "version": "2.0",
  "extensions": {
    "serviceBus": {
      "prefetchCount": 100,
      "messageHandlerOptions": {
        "autoComplete": true,
        "maxConcurrentCalls": 32,
        "maxAutoRenewDuration": "12:00:00"
      },
      "sessionHandlerOptions": {
        "autoComplete": false,
        "messageWaitTimeout": "00:00:30",
        "maxAutoRenewDuration": "12:00:00",
        "maxConcurrentSessions": 16
      },
      "batchOptions": {
        "maxMessageCount": 1000,
        "operationTimeout": "00:01:00",
        "autoComplete": true
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[3.3.0, 4.0.0)"
  }
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "java",
    "ServiceBusConnection": <endpoint>
  }
}

function.json

{
  "scriptFile": "ScalaFunction.jar",
  "entryPoint": "functions.Service.run",
  "bindings": [
    {
      "type": "serviceBusTrigger",
      "direction": "in",
      "queueName": "<queueName>",
      "name": "inMessage",
      "connection": "ServiceBusConnection"
    }
  ]
}

Calling method:

  @FunctionName("readSBQueue")
  def run(@ServiceBusQueueTrigger(name="inMessage",
    queueName = <queueName>,
    connection = "ServiceBusConnection") message: String,
          context: ExecutionContext
          ) = { ... }

Solution

  • Managed to solve it by trial and error. In function.json should have omitted the direction property resulting in:

    {
    "scriptFile": "ScalaFunction.jar",
      "entryPoint": "functions.Service.run",
      "bindings": [
        {
          "type": "serviceBusTrigger",
          "queueName": "<queueName>",
          "name": "inMessage",
          "connection": "ServiceBusConnection"
        }
      ]
    }