From 84a83cd574e266b6212f5e420c833b3667d1e617 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Sun, 7 Aug 2022 12:24:55 +0300 Subject: [PATCH] solution --- .../generator/KafkaMessageGenerator.java | 2 +- .../quarkus/kafka/EntityRepositoryImpl.java | 21 +++++++++++++++++++ .../example/quarkus/kafka/KafkaHandler.java | 4 ++-- .../quarkus/kafka/PanacheRepositoryImpl.java | 10 --------- .../src/main/resources/application.yml | 1 + 5 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/EntityRepositoryImpl.java delete mode 100644 quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/PanacheRepositoryImpl.java diff --git a/quarkus-kafka-panache-generator/src/main/java/dev/struchkov/example/quarkus/generator/KafkaMessageGenerator.java b/quarkus-kafka-panache-generator/src/main/java/dev/struchkov/example/quarkus/generator/KafkaMessageGenerator.java index 94c331e..dad2c60 100644 --- a/quarkus-kafka-panache-generator/src/main/java/dev/struchkov/example/quarkus/generator/KafkaMessageGenerator.java +++ b/quarkus-kafka-panache-generator/src/main/java/dev/struchkov/example/quarkus/generator/KafkaMessageGenerator.java @@ -21,7 +21,7 @@ public class KafkaMessageGenerator { public void start(@Observes StartupEvent ev) { - for (int i = 0; i < 20; i++) { + for (int i = 0; i < 50; i++) { final KafkaMessage kafkaMessage = new KafkaMessage(); kafkaMessage.setCount(i); telegramChannel.sendAndAwait(kafkaMessage); diff --git a/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/EntityRepositoryImpl.java b/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/EntityRepositoryImpl.java new file mode 100644 index 0000000..755b0e3 --- /dev/null +++ b/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/EntityRepositoryImpl.java @@ -0,0 +1,21 @@ +package dev.struchkov.example.quarkus.kafka; + +import io.smallrye.mutiny.Uni; +import lombok.RequiredArgsConstructor; +import org.hibernate.reactive.mutiny.Mutiny; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +@RequiredArgsConstructor +public class EntityRepositoryImpl { + + private final Mutiny.SessionFactory factory; + + public Uni save(EntityForDb entityForDb) { + return factory.withTransaction( + session -> session.merge(entityForDb) + ); + } + +} diff --git a/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/KafkaHandler.java b/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/KafkaHandler.java index d9e0790..4391db5 100644 --- a/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/KafkaHandler.java +++ b/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/KafkaHandler.java @@ -10,14 +10,14 @@ import javax.enterprise.context.ApplicationScoped; @RequiredArgsConstructor public class KafkaHandler { - private final PanacheRepositoryImpl panacheRepository; + private final EntityRepositoryImpl panacheRepository; @Incoming("test") public Uni handle(KafkaMessage message) { System.out.println("Получено сообщение " + message); final EntityForDb entityForDb = new EntityForDb(); entityForDb.setCount(message.getCount()); - return panacheRepository.persistAndFlush(entityForDb).replaceWithVoid(); + return panacheRepository.save(entityForDb).replaceWithVoid(); } } diff --git a/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/PanacheRepositoryImpl.java b/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/PanacheRepositoryImpl.java deleted file mode 100644 index 8bc3f87..0000000 --- a/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/PanacheRepositoryImpl.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.struchkov.example.quarkus.kafka; - -import io.quarkus.hibernate.reactive.panache.PanacheRepository; - -import javax.enterprise.context.ApplicationScoped; - -@ApplicationScoped -public class PanacheRepositoryImpl implements PanacheRepository { - -} diff --git a/quarkus-kafka-panache-problem/src/main/resources/application.yml b/quarkus-kafka-panache-problem/src/main/resources/application.yml index 45b22cb..b16a3b0 100644 --- a/quarkus-kafka-panache-problem/src/main/resources/application.yml +++ b/quarkus-kafka-panache-problem/src/main/resources/application.yml @@ -6,6 +6,7 @@ quarkus: jdbc: false reactive: url: postgresql://localhost:5432/quarkus_test + max-size: 20 hibernate-orm: database: generation: update