kubernetesquarkusbrokerknativefunq

Getting the response from a knative broker call


I'm using Quarkus framework and the library called Funq with knative event bindings... Meaning that, I'm listening to Kubernetes cloud events in my Quarkus application and it's working properly.

Just to illustrate there is a piece of code:

@Funq
@CloudEventMapping(trigger = "fakeEvent")
fun fakeEventListener(payload: String) {
    log.info("$payload")

    return "received"
}
curl -v "http://broker-ingress.knative-eventing.svc.cluster.local/brokerName/default" -X POST -H "Ce-Id: 1234" -H "Ce-Specversion: 1.0" -H "Ce-Type: fakeEvent" -H "Ce-Source: curl" -H "Content-Type: application/json" -d '"{}"'

Is there aNY way to send a curl to the broker and instead of receiving a 202 status code, I get the response for the function?

enter image description here

I know that I can use the return of the **fakeEventListener** to trigger another cloud event, but instead I need to have the response of this information in the caller (in the curl request for this example, or any http client library).

If that is not possible how to provide be able to synchronously get the response from funq POST calls?


Solution

  • It is not possible to get this when curling the Broker. The Broker allows to decouple the components and send events asynchrnously. Also there could be multiple Triggers behind the Broker.

    When you need the response of your Knative Function synchronously, you need to call the function directly (e.g. via curl).

    In case you don't want to lose the Broker and simply need the response of the Function somewhere, you can make use of the reply event of your Broker-Trigger: The response of your Triggers subscriber (the Function in your case) is sent back as a new event to the Broker. So you could add another Trigger (which filters on the response event type) and send this event somewhere, where the responses are handled.