我已经使用@TimerTrigger和@RabbitMQOutput注解设置了一个基本的Azure函数,如下所述: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");
}
}
不幸的是,当我在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)"
}
本地设置. json包含:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "java",
"rabbitMQConnectionAppSetting": "amqp://guest:guest@127.0.0.1:5672/"
}
}
builder.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
有人能指出我做错了什么吗?
1条答案
按热度按时间inn6fuwd1#
您所使用的
getLogger()
函数是导致出现空指针异常的原因。如果您不提供记录器名称,此函数将抛出此异常。
因此,它应该看起来像这样:
请参阅以下来自javapoint的文章。