From cbcc5117c5313c15a7b5c528099bd8c86ed542e1 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Wed, 9 Nov 2022 21:58:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=81=D0=BF=D0=BE=D1=81=D0=BE?= =?UTF-8?q?=D0=B1=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../generator/KafkaMessageGenerator.java | 1 - quarkus-kafka-panache-problem/pom.xml | 2 +- .../kafka/KafkaHandlerForNewVersion.java | 25 +++++++++++++++++++ ...er.java => KafkaHandlerForOldVersion.java} | 4 ++- .../quarkus/kafka/PanacheRepositoryImpl.java | 10 ++++++++ 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/KafkaHandlerForNewVersion.java rename quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/{KafkaHandler.java => KafkaHandlerForOldVersion.java} (83%) create 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 dad2c60..b28380b 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 @@ -19,7 +19,6 @@ public class KafkaMessageGenerator { this.telegramChannel = telegramChannel; } - public void start(@Observes StartupEvent ev) { for (int i = 0; i < 50; i++) { final KafkaMessage kafkaMessage = new KafkaMessage(); diff --git a/quarkus-kafka-panache-problem/pom.xml b/quarkus-kafka-panache-problem/pom.xml index 009e42d..e6baba8 100644 --- a/quarkus-kafka-panache-problem/pom.xml +++ b/quarkus-kafka-panache-problem/pom.xml @@ -15,7 +15,7 @@ UTF-8 quarkus-bom io.quarkus.platform - 2.11.2.Final + 2.14.0.Final true 3.0.0-M7 diff --git a/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/KafkaHandlerForNewVersion.java b/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/KafkaHandlerForNewVersion.java new file mode 100644 index 0000000..cd25d9b --- /dev/null +++ b/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/KafkaHandlerForNewVersion.java @@ -0,0 +1,25 @@ +package dev.struchkov.example.quarkus.kafka; + +import io.smallrye.mutiny.Uni; +import lombok.RequiredArgsConstructor; +import org.eclipse.microprofile.reactive.messaging.Incoming; + +import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.context.control.ActivateRequestContext; + +@ApplicationScoped +@RequiredArgsConstructor +public class KafkaHandlerForNewVersion { + + private final PanacheRepositoryImpl panacheRepository; + + @Incoming("test") + @ActivateRequestContext + public Uni handle(KafkaMessage message) { + System.out.println("Получено сообщение " + message); + final EntityForDb entityForDb = new EntityForDb(); + entityForDb.setCount(message.getCount()); + return panacheRepository.persistAndFlush(entityForDb).replaceWithVoid(); + } + +} 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/KafkaHandlerForOldVersion.java similarity index 83% rename from quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/KafkaHandler.java rename to quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/KafkaHandlerForOldVersion.java index 4391db5..b918072 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/KafkaHandlerForOldVersion.java @@ -5,14 +5,16 @@ import lombok.RequiredArgsConstructor; import org.eclipse.microprofile.reactive.messaging.Incoming; import javax.enterprise.context.ApplicationScoped; +import javax.enterprise.context.control.ActivateRequestContext; @ApplicationScoped @RequiredArgsConstructor -public class KafkaHandler { +public class KafkaHandlerForOldVersion { private final EntityRepositoryImpl panacheRepository; @Incoming("test") + @ActivateRequestContext public Uni handle(KafkaMessage message) { System.out.println("Получено сообщение " + message); final EntityForDb entityForDb = new EntityForDb(); 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 new file mode 100644 index 0000000..8bc3f87 --- /dev/null +++ b/quarkus-kafka-panache-problem/src/main/java/dev/struchkov/example/quarkus/kafka/PanacheRepositoryImpl.java @@ -0,0 +1,10 @@ +package dev.struchkov.example.quarkus.kafka; + +import io.quarkus.hibernate.reactive.panache.PanacheRepository; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class PanacheRepositoryImpl implements PanacheRepository { + +}