Search code examples
kotlinkubernetesquarkusknative

Is it possible to send KNative events using any kind of SDK in java/kotlin without relying on Http?


So I'm using quarkus and funqy to listen to knative events and it works like a charm.
The way I used to test it locally with minikube/kind can be followed in the steps below.

  • Created a kubernetes service containing the quarkus image that has the @funq annotation

  • Created a `kubernetes trigger` that will invoke the service when receive the "myOwnEvent" event

  • Create a `kubernetes namespace`(knativetutorial) so I can put everything togueter

  • Create a `kubernetes broker` for this namespace (named default)

  • Create a `kubernetes pod` just so I can get inside it to make curl requests to the broker

After my local setup is done I made a curl request from inside the kubernetes pod that I created.
The curl was something like that:

```shell

curl -v "http://broker-ingress.knative-eventing.svc.cluster.local/knativetutorial/default" -X POST -H "Ce-Id: 1234" -H "Ce-Specversion: 1.0" -H "Ce-Type: myOwnEvent" -H "Ce-Source: curl" -H "Content-Type: application/json" -d '"Start"'

```

And it worked I successfully was able to manually trigger an event that was received by my quarkus application.

Now my main goal is to create a new event in my application and not manually.

I found some solutions on the internet, but they are all using an http POST request to the broker from inside the application (basically what I did but in the code itself).

I try https://github.com/fabric8io/kubernetes-client but I also couldn't find a way to send/publish an event.

Is there any other solution or should I rely on http for that?


Solution

  • Knative Uses CloudEvents for message routing; in particular, CloudEvents over HTTP, as described in the Knative Eventing spec. If you're looking for a higher-level library, you can use the CloudEvents Java SDK, but it will still be HTTP underneath.

    Part of the goal of Knative Eventing is to work well with a large variety of programming languages without needing a specal-purpose SDK, so just using HTTP to post events is actually a design feature compared with implementing something like AMQP for sending.