cloudevents / sdk-java

Java SDK for CloudEvents
https://cloudevents.github.io/sdk-java/
Apache License 2.0
382 stars 156 forks source link

Micronaut module #442

Open untereiner opened 2 years ago

untereiner commented 2 years ago

Hi, I am using the Micronaut framework and I have been thinking using CloudEvents between my microservices. Would it be interesting to provide a Micronaut module with the same spirit of the spring boot one to this sdk ?

lszymik commented 2 years ago

Hello, I was also trying to use CloudEvents with Micronaut. It is not working out of the box. It will be very valuable to have integration.

pierDipi commented 2 years ago

Hello, I've never used Micronout, so I'm don't know if I can maintain the integration, however, I'd like to understand more about the integration with Micronout, does anyone of you have something to show? a public proof of concept?

BramMeerten commented 1 year ago

I got it working with a few lines of code using io.cloudevents:cloudevents-http-basic and io.micronaut:micronaut-http-client:

@Singleton
public class MyEventPublisher {

    @Inject
    private HttpClient httpClient;

    private final String BROKER_URI = "http://broker-ingress.knative-eventing.svc.cluster.local/my-broker-url";

    Mono<void> sendEvent(CloudEvent event) {
        var request = HttpRequest.POST(URI.create(BROKER_URI), event);
        HttpMessageFactory.createWriter(request::header, request::body).writeBinary(event);

        return Mono.from(httpClient.retrieve(request, Void.class));
    }
}

Would be nice though to get it working with a Declarative Client