From c21e80b63f7f5fcb1e124aa3e7b8adeb0df33cd2 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Fri, 9 Jun 2023 16:09:25 +0200 Subject: [PATCH] init kafka --- scenarios/distributed-kafka/pom.xml | 38 +++++ .../pom.xml | 130 ++++++++++++++++++ ...cationLocalPolyflowDistributedWithKafka.kt | 85 ++++++++++++ .../process-platform-view-only/pom.xml | 96 +++++++++++++ ...PlatformApplicationDistributedWithKafka.kt | 90 ++++++++++++ scenarios/pom.xml | 1 + 6 files changed, 440 insertions(+) create mode 100755 scenarios/distributed-kafka/pom.xml create mode 100755 scenarios/distributed-kafka/process-application-local-polyflow/pom.xml create mode 100755 scenarios/distributed-kafka/process-application-local-polyflow/src/main/kotlin/ExampleProcessApplicationLocalPolyflowDistributedWithKafka.kt create mode 100644 scenarios/distributed-kafka/process-platform-view-only/pom.xml create mode 100755 scenarios/distributed-kafka/process-platform-view-only/src/main/kotlin/ExamplePlatformApplicationDistributedWithKafka.kt diff --git a/scenarios/distributed-kafka/pom.xml b/scenarios/distributed-kafka/pom.xml new file mode 100755 index 00000000..cabd9a43 --- /dev/null +++ b/scenarios/distributed-kafka/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + + io.holunda.polyflow + polyflow-example-scenario-root + 3.8.3-SNAPSHOT + + + polyflow-example-scenario-distributed-kafka + POM: examples/${project.artifactId} + pom + + + true + + + + process-application-local-polyflow + process-platform-view-only + + + + + + org.axonframework + axon-server-connector + 4.6.7 + runtime + + + + + + + diff --git a/scenarios/distributed-kafka/process-application-local-polyflow/pom.xml b/scenarios/distributed-kafka/process-application-local-polyflow/pom.xml new file mode 100755 index 00000000..a5810514 --- /dev/null +++ b/scenarios/distributed-kafka/process-application-local-polyflow/pom.xml @@ -0,0 +1,130 @@ + + + 4.0.0 + + + io.holunda.polyflow + polyflow-example-scenario-distributed-kafka + 3.8.3-SNAPSHOT + + + example-distributed-kafka-process-application-local-polyflow + examples/${project.artifactId} + + + true + + + + + + io.holunda.polyflow + polyflow-example-approval-backend + + + io.holunda.polyflow + polyflow-taskpool-core + + + io.holunda.polyflow + polyflow-datapool-core + + + + io.holunda.polyflow + polyflow-camunda-bpm-taskpool-job-sender + + + + + org.postgresql + postgresql + runtime + + + org.flywaydb + flyway-core + + + + io.holunda + camunda-platform-7-autologin + + + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + org.springframework.boot + spring-boot-maven-plugin + + + + io.holunda.polyflow + polyflow-example-approval-backend + + + + + + + + + + frontend + + + !skipFrontend + + + + + io.holunda.polyflow + polyflow-example-approval-forms + + + + + + camunda-ce + + + !camunda-ee + + + + + org.camunda.bpm.springboot + camunda-bpm-spring-boot-starter-webapp + + + + + camunda-ee + + + camunda-ee + + + + + org.camunda.bpm.springboot + camunda-bpm-spring-boot-starter-webapp-ee + + + + + + diff --git a/scenarios/distributed-kafka/process-application-local-polyflow/src/main/kotlin/ExampleProcessApplicationLocalPolyflowDistributedWithKafka.kt b/scenarios/distributed-kafka/process-application-local-polyflow/src/main/kotlin/ExampleProcessApplicationLocalPolyflowDistributedWithKafka.kt new file mode 100755 index 00000000..b39c76d7 --- /dev/null +++ b/scenarios/distributed-kafka/process-application-local-polyflow/src/main/kotlin/ExampleProcessApplicationLocalPolyflowDistributedWithKafka.kt @@ -0,0 +1,85 @@ +package io.holunda.polyflow.example.process.approval + +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.SerializationFeature +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.thoughtworks.xstream.XStream +import com.thoughtworks.xstream.security.AnyTypePermission +import io.holunda.polyflow.bus.jackson.config.FallbackPayloadObjectMapperAutoConfiguration.Companion.PAYLOAD_OBJECT_MAPPER +import io.holunda.polyflow.bus.jackson.configurePolyflowJacksonObjectMapper +import io.holunda.polyflow.datapool.core.EnablePolyflowDataPool +import io.holunda.polyflow.taskpool.core.EnablePolyflowTaskPool +import org.axonframework.commandhandling.CommandBus +import org.axonframework.commandhandling.gateway.CommandGateway +import org.axonframework.commandhandling.gateway.DefaultCommandGateway +import org.axonframework.eventhandling.deadletter.jpa.DeadLetterEventEntry +import org.axonframework.eventhandling.tokenstore.jpa.TokenEntry +import org.axonframework.modelling.saga.repository.jpa.SagaEntry +import org.axonframework.serialization.xml.CompactDriver +import org.axonframework.springboot.util.ConditionalOnMissingQualifiedBean +import org.axonframework.springboot.util.XStreamSecurityTypeUtility +import org.springframework.beans.factory.annotation.Qualifier +import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean +import org.springframework.boot.autoconfigure.domain.EntityScan +import org.springframework.context.ApplicationContext +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Import +import org.springframework.context.annotation.Primary + +/** + * Starts example application approval process. + */ +fun main(args: Array) { + SpringApplication.run(ExampleProcessApplicationLocalPolyflowDistributedWithKafka::class.java, *args) +} + +/** + * Process application approval only. + * Includes: + * - approval-process-backend + * - taskpool-core + * - datapool-core + */ +@SpringBootApplication +@EnablePolyflowDataPool +@EnablePolyflowTaskPool +@Import(RequestApprovalProcessConfiguration::class) +@EntityScan( + basePackageClasses = [ + TokenEntry::class, + SagaEntry::class, + DeadLetterEventEntry::class + ] +) +class ExampleProcessApplicationLocalPolyflowDistributedWithKafka { + + @Bean + fun objectMapper(): ObjectMapper { + return jacksonObjectMapper() + .registerModule(JavaTimeModule()) + .configurePolyflowJacksonObjectMapper() + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) + } + + @Bean("defaultAxonXStream") + @ConditionalOnMissingBean + fun defaultAxonXStream(applicationContext: ApplicationContext): XStream { + val xStream = XStream(CompactDriver()) + xStream.allowTypesByWildcard(XStreamSecurityTypeUtility.autoConfigBasePackages(applicationContext)) + // This configures XStream to permit any class to be deserialized. + // FIXME: We might want to make this more restrictive to improve security + xStream.addPermission(AnyTypePermission.ANY) + return xStream + } + + /* + @Bean + @Primary + @ConditionalOnMissingQualifiedBean(beanClass = CommandGateway::class, qualifier = "unqualified") + fun defaultCommandGateway(bus: CommandBus): CommandGateway = DefaultCommandGateway.builder().commandBus(bus).build() + */ + +} diff --git a/scenarios/distributed-kafka/process-platform-view-only/pom.xml b/scenarios/distributed-kafka/process-platform-view-only/pom.xml new file mode 100644 index 00000000..eab367a5 --- /dev/null +++ b/scenarios/distributed-kafka/process-platform-view-only/pom.xml @@ -0,0 +1,96 @@ + + + 4.0.0 + + + io.holunda.polyflow + polyflow-example-scenario-distributed-kafka + 3.8.3-SNAPSHOT + + + example-distributed-kafka-process-platform-view-only + examples/${project.artifactId} + + + true + + + + + io.holunda.polyflow + polyflow-example-tasklist-backend + + + io.holunda.polyflow + polyflow-form-url-resolver + + + io.holunda.polyflow + polyflow-view-jpa + + + + org.flywaydb + flyway-core + + + org.postgresql + postgresql + runtime + + + + + org.axonframework + axon-spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-web + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + com.fasterxml.jackson.module + jackson-module-kotlin + + + + org.springdoc + springdoc-openapi-ui + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + frontend + + + !skipFrontend + + + + + io.holunda.polyflow + polyflow-example-tasklist-angular + + + + + + diff --git a/scenarios/distributed-kafka/process-platform-view-only/src/main/kotlin/ExamplePlatformApplicationDistributedWithKafka.kt b/scenarios/distributed-kafka/process-platform-view-only/src/main/kotlin/ExamplePlatformApplicationDistributedWithKafka.kt new file mode 100755 index 00000000..fec5932b --- /dev/null +++ b/scenarios/distributed-kafka/process-platform-view-only/src/main/kotlin/ExamplePlatformApplicationDistributedWithKafka.kt @@ -0,0 +1,90 @@ +package io.holunda.polyflow.example.process.platform + +import com.fasterxml.jackson.databind.DeserializationFeature +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.databind.SerializationFeature +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper +import com.thoughtworks.xstream.XStream +import com.thoughtworks.xstream.security.AnyTypePermission +import io.holixon.axon.gateway.query.RevisionValue +import io.holunda.polyflow.bus.jackson.config.FallbackPayloadObjectMapperAutoConfiguration.Companion.PAYLOAD_OBJECT_MAPPER +import io.holunda.polyflow.bus.jackson.configurePolyflowJacksonObjectMapper +import io.holunda.polyflow.example.tasklist.EnableTasklist +import io.holunda.polyflow.example.users.EnableExampleUsers +import io.holunda.polyflow.example.users.UsersConfiguration +import io.holunda.polyflow.urlresolver.EnablePropertyBasedFormUrlResolver +import io.holunda.polyflow.view.jpa.EnablePolyflowJpaView +import org.axonframework.commandhandling.CommandMessage +import org.axonframework.messaging.correlation.CorrelationDataProvider +import org.axonframework.messaging.correlation.MessageOriginProvider +import org.axonframework.messaging.correlation.MultiCorrelationDataProvider +import org.axonframework.messaging.correlation.SimpleCorrelationDataProvider +import org.axonframework.serialization.xml.CompactDriver +import org.axonframework.springboot.util.XStreamSecurityTypeUtility +import org.springframework.beans.factory.annotation.Qualifier +import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean +import org.springframework.context.ApplicationContext +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Primary + +/** + * Starts platform application. + */ +fun main(args: Array) { + SpringApplication.run(ExamplePlatformApplicationDistributedWithKafka::class.java, *args) +} + +/** + * Process application using Axon Server as event store and communication platform. + * Includes: + * - jpa view + * - tasklist backend + */ +@SpringBootApplication +@EnableExampleUsers +@EnableTasklist +@EnablePropertyBasedFormUrlResolver +@EnablePolyflowJpaView +class ExamplePlatformApplicationDistributedWithKafka { + + @Qualifier(PAYLOAD_OBJECT_MAPPER) + @Bean + @Primary + fun payloadObjectMapper(): ObjectMapper { + return jacksonObjectMapper() + .registerModule(JavaTimeModule()) + .configurePolyflowJacksonObjectMapper() + .disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) // let the dates be strings and not nanoseconds + .disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES) // be nice to properties we don't understand + } + + @Bean("defaultAxonXStream") + @ConditionalOnMissingBean + fun defaultAxonXStream(applicationContext: ApplicationContext): XStream { + val xStream = XStream(CompactDriver()) + xStream.allowTypesByWildcard(XStreamSecurityTypeUtility.autoConfigBasePackages(applicationContext)) + // This configures XStream to permit any class to be deserialized. + // FIXME: We might want to make this more restrictive to improve security + xStream.addPermission(AnyTypePermission.ANY) + return xStream + } + + /** + * Factory function creating correlation data provider for revision information. + * We don't want to explicitly pump revision meta data from command to event. + */ + @Bean + fun revisionAwareCorrelationDataProvider(): CorrelationDataProvider { + return MultiCorrelationDataProvider>( + listOf( + MessageOriginProvider(), + SimpleCorrelationDataProvider(RevisionValue.REVISION_KEY) + ) + ) + } +} + + diff --git a/scenarios/pom.xml b/scenarios/pom.xml index e96e7228..d25339de 100755 --- a/scenarios/pom.xml +++ b/scenarios/pom.xml @@ -22,6 +22,7 @@ single-node-jpa-maria distributed-axon-server distributed-axon-server-local-polyflow + distributed-kafka