Azure-Samples / hello-spring-function-azure

Example "Hello, world" Spring Boot application that runs on Azure Functions
MIT License
68 stars 87 forks source link

EventHubTrigger not working with Spring Cloud #17

Closed ghost closed 4 years ago

ghost commented 4 years ago

I’am working on integrating the Azure EventHubTrigger Function with Spring Cloud Functions. I followed the below link which explains how HttpTrigger Function delegates the request to Spring Cloud. https://docs.microsoft.com/en-us/azure/developer/java/spring-framework/getting-started-with-spring-cloud-function-in-azure When I try the same with EventHubTrigger, I get “Exception: IllegalStateException: No function defined”. Below is the screenshot of the log.

image image image

jdubois commented 4 years ago

It's hard to tell as I'm not using this at all in this sample (this is why I'm closing this). But it looks like a usual bug we had here: please use the latest version of the Maven plugin, and be sure to add the <start-class>com.example.HelloFunction</start-class> property in your pom.xml. It's one of the different ways to make Azure Function knows where your function is (there are 2 other ways to do it, so if it doesn't work please add a comment).

ghost commented 4 years ago

Iam using org.iot.enrichment.EventFunction which specifies the MainFunction in pom.xml file.

jdubois commented 4 years ago

Then I'm sorry because I don't know this at all. I'm only using the HTTP trigger in this sample.

ghost commented 4 years ago

Also, When I run @HttpTriger Azure function using terminal it works as expected. The same code If I run using IntelliJ IDE it throws below exception in handleRequest method.

image

Exception: NoSuchElementException: No value present Stack: java.lang.reflect.InvocationTargetException [6/29/2020 7:08:35 PM] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [6/29/2020 7:08:35 PM] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [6/29/2020 7:08:35 PM] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [6/29/2020 7:08:35 PM] at java.lang.reflect.Method.invoke(Method.java:498) [6/29/2020 7:08:35 PM] at com.microsoft.azure.functions.worker.broker.JavaMethodInvokeInfo.invoke(JavaMethodInvokeInfo.java:22) [6/29/2020 7:08:35 PM] at com.microsoft.azure.functions.worker.broker.JavaMethodExecutor.execute(JavaMethodExecutor.java:54) [6/29/2020 7:08:35 PM] at com.microsoft.azure.functions.worker.broker.JavaFunctionBroker.invokeMethod(JavaFunctionBroker.java:53) [6/29/2020 7:08:35 PM] at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:33) [6/29/2020 7:08:35 PM] at com.microsoft.azure.functions.worker.handler.InvocationRequestHandler.execute(InvocationRequestHandler.java:10) [6/29/2020 7:08:35 PM] at com.microsoft.azure.functions.worker.handler.MessageHandler.handle(MessageHandler.java:45) [6/29/2020 7:08:35 PM] at com.microsoft.azure.functions.worker.JavaWorkerClient$StreamingMessagePeer.lambda$onNext$0(JavaWorkerClient.java:92) [6/29/2020 7:08:35 PM] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [6/29/2020 7:08:35 PM] at java.util.concurrent.FutureTask.run(FutureTask.java:266) [6/29/2020 7:08:35 PM] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [6/29/2020 7:08:35 PM] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [6/29/2020 7:08:35 PM] at java.lang.Thread.run(Thread.java:748) [6/29/2020 7:08:35 PM] Caused by: java.util.NoSuchElementException: No value present [6/29/2020 7:08:35 PM] at java.util.Optional.get(Optional.java:135) [6/29/2020 7:08:35 PM] at com.example.HelloHandler.execute(HelloHandler.java:20) [6/29/2020 7:08:35 PM] ... 16 more [6/29/2020 7:08:35 PM] . [6/29/2020 7:08:35 PM] Executed HTTP request: { [6/29/2020 7:08:35 PM] "requestId": "1295155a-7423-456c-bd25-cd90f0a8a23f", [6/29/2020 7:08:35 PM] "method": "GET", [6/29/2020 7:08:35 PM] "uri": "/api/hello", [6/29/2020 7:08:35 PM] "identities": [ [6/29/2020 7:08:35 PM] { [6/29/2020 7:08:35 PM] "type": "WebJobsAuthLevel", [6/29/2020 7:08:35 PM] "level": "Admin" [6/29/2020 7:08:35 PM] } [6/29/2020 7:08:35 PM] ], [6/29/2020 7:08:35 PM] "status": 500, [6/29/2020 7:08:35 PM] "duration": 74 [6/29/2020 7:08:35 PM] }

jdubois commented 4 years ago

I've only used the Maven plugin to run the code. I believe there is also an Intellij plugin, are you using this?

ghost commented 4 years ago

Yes, I have installed Azure took kit plugin in Intellij which provide provision for using azure functions.

jdubois commented 4 years ago

Oh, in that case it's easy! First of all, I add back this property https://github.com/Azure-Samples/hello-spring-function-azure/commit/b72f1ce362517020dd28a77e20e6de5fbf9bb7d8 if you need to run this using the Maven plugin. You need to set up the same property in your Azure Functions set up screen, like in the screenshot below: Screenshot 2020-06-30 at 17 05 57

ghost commented 4 years ago

Hi,

Whom I need to contact for integrating EventHubTrigger functionality with Spring cloud? This is very urgent.

jdubois commented 4 years ago

@DhivyaDhivosh let's discuss this on https://github.com/Azure-Samples/hello-spring-function-azure/issues/18 as you created another ticket for that