Changeset 24:663d97e943f9

Added event dispatcher and fixed dependencies
author unexist
date Tue, 17 Aug 2021 11:31:42 +0200
parents c98833c3f4c4
children 12a32467beb6
files event-split-extension-parent/deployment/pom.xml event-split-extension-parent/deployment/src/main/java/dev/unexist/showcase/eventsplit/EventSplitProcessor.java event-split-extension-parent/runtime/pom.xml event-split-extension-parent/runtime/src/main/java/dev/unexist/showcase/eventsplit/EventSplitDispatcher.java event-split-extension-parent/runtime/src/main/resources/META-INF/quarkus-extension.yaml
diffstat 5 files changed, 117 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/event-split-extension-parent/deployment/pom.xml	Mon Aug 16 17:09:44 2021 +0200
+++ b/event-split-extension-parent/deployment/pom.xml	Tue Aug 17 11:31:42 2021 +0200
@@ -13,20 +13,26 @@
     </parent>
 
     <dependencies>
+        <!-- Quarkus -->
         <dependency>
             <groupId>io.quarkus</groupId>
             <artifactId>quarkus-arc-deployment</artifactId>
         </dependency>
         <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-vertx-deployment</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>io.quarkus</groupId>
+            <artifactId>quarkus-smallrye-reactive-messaging-kafka-deployment</artifactId>
+        </dependency>
+
+        <!-- Runtime artifact -->
+        <dependency>
             <groupId>dev.unexist.showcase</groupId>
             <artifactId>event-split-extension</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <dependency>
-            <groupId>io.quarkus</groupId>
-            <artifactId>quarkus-junit5-internal</artifactId>
-            <scope>test</scope>
-        </dependency>
     </dependencies>
 
     <build>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/event-split-extension-parent/deployment/src/main/java/dev/unexist/showcase/eventsplit/EventSplitProcessor.java	Tue Aug 17 11:31:42 2021 +0200
@@ -0,0 +1,24 @@
+/**
+ * @package Showcase
+ *
+ * @file Extension processor
+ * @copyright 2021 Christoph Kappel <christoph@unexist.dev>
+ * @version $Id$
+ *
+ * This program can be distributed under the terms of the Apache License v2.0.
+ * See the file LICENSE for details.
+ **/
+
+package dev.unexist.showcase.eventsplit;
+
+import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.builditem.FeatureBuildItem;
+
+public class EventSplitProcessor {
+    private static final String EVENT_SPLIT = "event-split";
+
+    @BuildStep
+    FeatureBuildItem feature() {
+        return new FeatureBuildItem(EVENT_SPLIT);
+    }
+}
--- a/event-split-extension-parent/runtime/pom.xml	Mon Aug 16 17:09:44 2021 +0200
+++ b/event-split-extension-parent/runtime/pom.xml	Tue Aug 17 11:31:42 2021 +0200
@@ -13,10 +13,16 @@
     </parent>
 
     <properties>
+        <!-- Smallrye -->
         <smallrye-reactive-messaging-vertx-eventbus.version>3.1.0</smallrye-reactive-messaging-vertx-eventbus.version>
+
+        <!-- Util -->
+        <apache-commons-lang.version>3.12.0</apache-commons-lang.version>
+        <jackson-databind.version>2.13.0-rc1</jackson-databind.version>
     </properties>
 
     <dependencies>
+        <!-- Quarkus -->
         <dependency>
             <groupId>io.quarkus</groupId>
             <artifactId>quarkus-arc</artifactId>
@@ -36,6 +42,18 @@
             <artifactId>smallrye-reactive-messaging-vertx-eventbus</artifactId>
             <version>${smallrye-reactive-messaging-vertx-eventbus.version}</version>
         </dependency>
+
+        <!-- Util -->
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-lang3</artifactId>
+            <version>${apache-commons-lang.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.fasterxml.jackson.core</groupId>
+            <artifactId>jackson-databind</artifactId>
+            <version>${jackson-databind.version}</version>
+        </dependency>
     </dependencies>
 
     <build>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/event-split-extension-parent/runtime/src/main/java/dev/unexist/showcase/eventsplit/EventSplitDispatcher.java	Tue Aug 17 11:31:42 2021 +0200
@@ -0,0 +1,52 @@
+/**
+ * @package Showcase
+ *
+ * @file Event dispatcher
+ * @copyright 2021 Christoph Kappel <christoph@unexist.dev>
+ * @version $Id$
+ *
+ * This program can be distributed under the terms of the Apache License v2.0.
+ * See the file LICENSE for details.
+ **/
+ 
+package dev.unexist.showcase.eventsplit;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.vertx.core.eventbus.EventBus;
+import org.apache.commons.lang3.StringUtils;
+import org.eclipse.microprofile.reactive.messaging.Channel;
+import org.eclipse.microprofile.reactive.messaging.Message;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import java.util.concurrent.CompletionStage;
+
+@ApplicationScoped
+public class EventSplitDispatcher {
+    private final static ObjectMapper MAPPER = new ObjectMapper();
+
+    @Inject
+    EventBus bus;
+
+    @Channel("todo_in")
+    private CompletionStage<Void> dispatchEvents(Message message) {
+        String payload = (String) message.getPayload();
+        String typeName = StringUtils.EMPTY;
+
+        System.out.println("Handle message " + payload);
+
+        try {
+            JsonNode json = MAPPER.readTree(payload);
+
+            typeName = json.get("type").asText();
+        } catch (JsonProcessingException e) {
+            System.out.println("Error reading JSON " + e);
+        }
+
+        this.bus.send(typeName, message);
+
+        return message.ack();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/event-split-extension-parent/runtime/src/main/resources/META-INF/quarkus-extension.yaml	Tue Aug 17 11:31:42 2021 +0200
@@ -0,0 +1,12 @@
+---
+name: "Event Splitter for Quarkus"
+description: "Splits a single event into multiple EventBus events"
+metadata:
+  keywords:
+    - "kafka"
+    - "eventbus"
+    - "cdc"
+  guide: "https://unexist.dev"
+  categories:
+    - "integration"
+  status: "experimental"
\ No newline at end of file