尝试测试本地兔子时,接收NullPoInterException

发布于 2025-02-01 09:19:44 字数 5125 浏览 3 评论 0 原文

我已经使用@timertrigger和@rabbitmqoutput注释设置了基本的Azure函数: https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-rabbitmq?tabs = in-process&pivots = pivots = progivots = programming-language-java

public class RabbitMQFunction {
    private static final Logger logger = LoggerFactory.getLogger(RabbitMQFunction.class);
    /**
     * This function will be invoked periodically according to the specified schedule.
     */
    @FunctionName("RabbitMQFunction")
    public void run(
        @TimerTrigger(name = "timerInfo", schedule = "*/15 * * * * *") String timerInfo,
        @RabbitMQOutput(connectionStringSetting = "rabbitMQConnectionAppSetting", queueName = "myQueue", disableCertificateValidation = true) OutputBinding<String> output,
        final ExecutionContext context
    ) {
        logger.debug("START - RabbitMQFunction");
        context.getLogger().info("Java Timer trigger function executed at: " + LocalDateTime.now());
        output.setValue("Some string");
        logger.debug("END - RabbitMQFunction");
    }
}

不幸的是,我在Visual Studio代码中使用Azurite本地测试时,在输出中接收以下错误。这是堆栈跟踪:

[2022-05-24T13:46:48.878Z] Received FunctionLoadResponse for function: 'RabbitMQFunction' with functionId: 'b09d265b-8b35-478f-8657-da7cf5b0fbc6'.
[2022-05-24T13:46:49.529Z] Host lock lease acquired by instance ID '000000000000000000000000CEA4F55C'.
[2022-05-24T13:47:00.087Z] Executing 'Functions.RabbitMQFunction' (Reason='Timer fired at 2022-05-24T09:47:00.0322362-04:00', Id=a34b49d5-603f-4977-92f0-672f0d5feb86)
[2022-05-24T13:47:00.243Z] InvocationResponse received for invocation id: 'a34b49d5-603f-4977-92f0-672f0d5feb86'
[2022-05-24T13:47:00.325Z] Executed 'Functions.RabbitMQFunction' (Failed, Id=a34b49d5-603f-4977-92f0-672f0d5feb86, Duration=265ms)
[2022-05-24T13:47:00.327Z] System.Private.CoreLib: Exception while executing function: Functions.RabbitMQFunction. System.Private.CoreLib: Result: Failure
Exception: NullPointerException:
Stack: java.lang.NullPointerException
[2022-05-24T13:47:00.329Z]      at com.microsoft.azure.functions.worker.binding.BindingDataStore.isDataTargetValid(BindingDataStore.java:145)       
[2022-05-24T13:47:00.331Z]      at com.microsoft.azure.functions.worker.binding.BindingDataStore.getOrAddDataTarget(BindingDataStore.java:123)      
[2022-05-24T13:47:00.333Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:56)
[2022-05-24T13:47:00.334Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:42)
[2022-05-24T13:47:00.336Z]      at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:53)
[2022-05-24T13:47:00.338Z]      at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:61)
[2022-05-24T13:47:00.339Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:33)  
[2022-05-24T13:47:00.341Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)  
[2022-05-24T13:47:00.342Z]      at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45)
[2022-05-24T13:47:00.344Z]      at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92)
[2022-05-24T13:47:00.345Z]      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[2022-05-24T13:47:00.347Z]      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[2022-05-24T13:47:00.349Z]      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[2022-05-24T13:47:00.351Z]      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[2022-05-24T13:47:00.352Z]      at java.base/java.lang.Thread.run(Thread.java:829)
[2022-05-24T13:47:00.354Z] .

host.json包含:

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  }

local.settings.json包含:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "java",
    "rabbitMQConnectionAppSetting": "amqp://guest:[email protected]:5672/"
  }
}

build.gradle包含:

implementation 'com.microsoft.azure.functions:azure-functions-java-library:2.0.1'
implementation 'com.microsoft.azure.functions:azure-functions-java-library-rabbitmq:1.0.0'
// I've also tried with 2.0.0-preview

有人可以指出我在做什么错吗?

I've setup a basic Azure function with the @TimerTrigger and @RabbitMQOutput annotations as mentioned here:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-rabbitmq?tabs=in-process&pivots=programming-language-java

public class RabbitMQFunction {
    private static final Logger logger = LoggerFactory.getLogger(RabbitMQFunction.class);
    /**
     * This function will be invoked periodically according to the specified schedule.
     */
    @FunctionName("RabbitMQFunction")
    public void run(
        @TimerTrigger(name = "timerInfo", schedule = "*/15 * * * * *") String timerInfo,
        @RabbitMQOutput(connectionStringSetting = "rabbitMQConnectionAppSetting", queueName = "myQueue", disableCertificateValidation = true) OutputBinding<String> output,
        final ExecutionContext context
    ) {
        logger.debug("START - RabbitMQFunction");
        context.getLogger().info("Java Timer trigger function executed at: " + LocalDateTime.now());
        output.setValue("Some string");
        logger.debug("END - RabbitMQFunction");
    }
}

Unfortunately, I'm receiving the following error in the output when testing locally with Azurite in Visual Studio Code. Here's the stack trace:

[2022-05-24T13:46:48.878Z] Received FunctionLoadResponse for function: 'RabbitMQFunction' with functionId: 'b09d265b-8b35-478f-8657-da7cf5b0fbc6'.
[2022-05-24T13:46:49.529Z] Host lock lease acquired by instance ID '000000000000000000000000CEA4F55C'.
[2022-05-24T13:47:00.087Z] Executing 'Functions.RabbitMQFunction' (Reason='Timer fired at 2022-05-24T09:47:00.0322362-04:00', Id=a34b49d5-603f-4977-92f0-672f0d5feb86)
[2022-05-24T13:47:00.243Z] InvocationResponse received for invocation id: 'a34b49d5-603f-4977-92f0-672f0d5feb86'
[2022-05-24T13:47:00.325Z] Executed 'Functions.RabbitMQFunction' (Failed, Id=a34b49d5-603f-4977-92f0-672f0d5feb86, Duration=265ms)
[2022-05-24T13:47:00.327Z] System.Private.CoreLib: Exception while executing function: Functions.RabbitMQFunction. System.Private.CoreLib: Result: Failure
Exception: NullPointerException:
Stack: java.lang.NullPointerException
[2022-05-24T13:47:00.329Z]      at com.microsoft.azure.functions.worker.binding.BindingDataStore.isDataTargetValid(BindingDataStore.java:145)       
[2022-05-24T13:47:00.331Z]      at com.microsoft.azure.functions.worker.binding.BindingDataStore.getOrAddDataTarget(BindingDataStore.java:123)      
[2022-05-24T13:47:00.333Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:56)
[2022-05-24T13:47:00.334Z]      at com.microsoft.azure.functions.worker.broker.ParameterResolver.resolve(ParameterResolver.java:42)
[2022-05-24T13:47:00.336Z]      at com.microsoft.azure.functions.worker.broker.EnhancedJavaMethodExecutorImpl.execute(EnhancedJavaMethodExecutorImpl.java:53)
[2022-05-24T13:47:00.338Z]      at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:61)
[2022-05-24T13:47:00.339Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:33)  
[2022-05-24T13:47:00.341Z]      at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10)  
[2022-05-24T13:47:00.342Z]      at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45)
[2022-05-24T13:47:00.344Z]      at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92)
[2022-05-24T13:47:00.345Z]      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[2022-05-24T13:47:00.347Z]      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[2022-05-24T13:47:00.349Z]      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
[2022-05-24T13:47:00.351Z]      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
[2022-05-24T13:47:00.352Z]      at java.base/java.lang.Thread.run(Thread.java:829)
[2022-05-24T13:47:00.354Z] .

host.json contains:

{
  "version": "2.0",
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  }

local.settings.json contains:

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "java",
    "rabbitMQConnectionAppSetting": "amqp://guest:[email protected]:5672/"
  }
}

build.gradle contains:

implementation 'com.microsoft.azure.functions:azure-functions-java-library:2.0.1'
implementation 'com.microsoft.azure.functions:azure-functions-java-library-rabbitmq:1.0.0'
// I've also tried with 2.0.0-preview

Can someone point out what I'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小梨窩很甜 2025-02-08 09:19:44

您使用的 getLogger()函数是获取NULL指针异常的原因。

如果您不提供Logger名称,则此功能将引发此异常。

因此,它应该看起来像:

context.getLogger(RabbitMQFunction.class)

请参阅此 Javapoint的文章。

The getLogger() function you have used is the reason for getting the null pointer exception.

This function will throw this exception if you don't provide a logger name.

So, this it should look like:

context.getLogger(RabbitMQFunction.class)

Refer this following article from javapoint.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文