diff --git a/docs/src/main/asciidoc/kafka.adoc b/docs/src/main/asciidoc/kafka.adoc index 16a772de5124d..147f0b6dc30e7 100644 --- a/docs/src/main/asciidoc/kafka.adoc +++ b/docs/src/main/asciidoc/kafka.adoc @@ -2956,9 +2956,7 @@ NOTE: If you use Hibernate Reactive, look at < emitter; + @Channel("kafka") MutinyEmitter emitter; @POST @Path("/fruits") - @Transactional // <1> - public CompletionStage storeAndSendToKafka(Fruit fruit) { // <2> + @Transactional // <1> + public void storeAndSendToKafka(Fruit fruit) { // <2> fruit.persist(); - return emitter.send(new FruitDto(fruit)); // <3> + emitter.sendAndAwait(new FruitDto(fruit)); // <3> } } ---- <1> As we are writing to the database, make sure we run inside a transaction -<2> The method receives the fruit instance to persist. It returns a `CompletionStage` which is used for the transaction demarcation. The transaction is committed when the return `CompletionStage` completes. In our case, it's when the message is written to Kafka. +<2> The method receives the fruit instance to persist. <3> Wrap the managed entity inside a Data transfer object and send it to Kafka. This makes sure that managed entity is not impacted by the Kafka serialization. +Then await the completion of the operation before returning. + +NOTE: You should not return a `CompletionStage` or `Uni` when using `@Transactional`, as all transaction commits will happen on a single thread, which impacts performance. [[writing-entities-managed-by-hibernate-reactive-to-kafka]] === Writing entities managed by Hibernate Reactive to Kafka