Skip to content

Commit

Permalink
Merge pull request #321 from AxonFramework/feature/add-cloudeventseri…
Browse files Browse the repository at this point in the history
…alizer

Add Cloud event serializer
  • Loading branch information
smcvb committed Sep 15, 2022
2 parents a3708a4 + 284ce93 commit a12b98b
Show file tree
Hide file tree
Showing 26 changed files with 1,725 additions and 125 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
~ Copyright (c) 2010-2022. Axon Framework
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Kafka Axon Example - PooledStreaming Producer and Consumer using Cloud Events"
type="JetRunConfigurationType" folderName="Kafka Axon Example">
<option name="MAIN_CLASS_NAME"
value="org.axonframework.extensions.kafka.example.KafkaAxonExampleApplicationKt"/>
<module name="kafka-axon-example"/>
<option name="PROGRAM_PARAMETERS"
value="--spring.profiles.active=pooled-streaming-producer,pooled-streaming-consumer,cloud-event"/>
<shortenClasspath name="NONE"/>
<method v="2">
<option name="Make" enabled="true"/>
</method>
</configuration>
</component>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2010-2021. Axon Framework
~ Copyright (c) 2010-2022. Axon Framework
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Kafka Axon Example - PooledStreaming Producer and Consumer" type="JetRunConfigurationType" folderName="Kafka Axon Example">
<option name="MAIN_CLASS_NAME" value="org.axonframework.extensions.kafka.example.KafkaAxonExampleApplicationKt" />
<module name="axon-kafka-example" />
<module name="kafka-axon-example"/>
<option name="PROGRAM_PARAMETERS" value="--spring.profiles.active=pooled-streaming-producer,pooled-streaming-consumer" />
<shortenClasspath name="NONE" />
<method v="2">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2010-2021. Axon Framework
~ Copyright (c) 2010-2022. Axon Framework
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Kafka Axon Example - PooledStreaming Producer and Subscribing Consumer" type="JetRunConfigurationType" folderName="Kafka Axon Example">
<option name="MAIN_CLASS_NAME" value="org.axonframework.extensions.kafka.example.KafkaAxonExampleApplicationKt" />
<module name="axon-kafka-example" />
<module name="kafka-axon-example"/>
<option name="PROGRAM_PARAMETERS" value="--spring.profiles.active=pooled-streaming-producer,subscribing-consumer" />
<shortenClasspath name="NONE" />
<method v="2">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2010-2021. Axon Framework
~ Copyright (c) 2010-2022. Axon Framework
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Kafka Axon Example - PooledStreaming Producer and Tracking Consumer" type="JetRunConfigurationType" folderName="Kafka Axon Example">
<option name="MAIN_CLASS_NAME" value="org.axonframework.extensions.kafka.example.KafkaAxonExampleApplicationKt" />
<module name="axon-kafka-example" />
<module name="kafka-axon-example"/>
<option name="PROGRAM_PARAMETERS" value="--spring.profiles.active=pooled-streaming-producer,tracking-consumer" />
<shortenClasspath name="NONE" />
<method v="2">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2010-2021. Axon Framework
~ Copyright (c) 2010-2022. Axon Framework
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Kafka Axon Example - Subscribing Producer and Consumer" type="JetRunConfigurationType" folderName="Kafka Axon Example">
<option name="MAIN_CLASS_NAME" value="org.axonframework.extensions.kafka.example.KafkaAxonExampleApplicationKt" />
<module name="axon-kafka-example" />
<module name="kafka-axon-example"/>
<option name="PROGRAM_PARAMETERS" value="--spring.profiles.active=subscribing-producer,subscribing-consumer" />
<shortenClasspath name="NONE" />
<method v="2">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2010-2021. Axon Framework
~ Copyright (c) 2010-2022. Axon Framework
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Kafka Axon Example - Subscribing Producer and PooledStreaming Consumer" type="JetRunConfigurationType" folderName="Kafka Axon Example">
<option name="MAIN_CLASS_NAME" value="org.axonframework.extensions.kafka.example.KafkaAxonExampleApplicationKt" />
<module name="axon-kafka-example" />
<module name="kafka-axon-example"/>
<option name="PROGRAM_PARAMETERS" value="--spring.profiles.active=subscribing-producer,pooled-streaming-consumer" />
<shortenClasspath name="NONE" />
<method v="2">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2010-2021. Axon Framework
~ Copyright (c) 2010-2022. Axon Framework
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Kafka Axon Example - Subscribing Producer and Tracking Consumer" type="JetRunConfigurationType" folderName="Kafka Axon Example">
<option name="MAIN_CLASS_NAME" value="org.axonframework.extensions.kafka.example.KafkaAxonExampleApplicationKt" />
<module name="axon-kafka-example" />
<module name="kafka-axon-example"/>
<option name="PROGRAM_PARAMETERS" value="--spring.profiles.active=subscribing-producer,tracking-consumer" />
<shortenClasspath name="NONE" />
<method v="2">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2010-2021. Axon Framework
~ Copyright (c) 2010-2022. Axon Framework
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Kafka Axon Example - Tracking Producer and Consumer" type="JetRunConfigurationType" folderName="Kafka Axon Example">
<option name="MAIN_CLASS_NAME" value="org.axonframework.extensions.kafka.example.KafkaAxonExampleApplicationKt" />
<module name="axon-kafka-example" />
<module name="kafka-axon-example"/>
<option name="PROGRAM_PARAMETERS" value="--spring.profiles.active=tracking-producer,tracking-consumer" />
<shortenClasspath name="NONE" />
<method v="2">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2010-2021. Axon Framework
~ Copyright (c) 2010-2022. Axon Framework
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Kafka Axon Example - Tracking Producer and PooledStreaming Consumer" type="JetRunConfigurationType" folderName="Kafka Axon Example">
<option name="MAIN_CLASS_NAME" value="org.axonframework.extensions.kafka.example.KafkaAxonExampleApplicationKt" />
<module name="axon-kafka-example" />
<module name="kafka-axon-example"/>
<option name="PROGRAM_PARAMETERS" value="--spring.profiles.active=tracking-producer,pooled-streaming-consumer" />
<shortenClasspath name="NONE" />
<method v="2">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
~ Copyright (c) 2010-2021. Axon Framework
~ Copyright (c) 2010-2022. Axon Framework
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,7 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Kafka Axon Example - Tracking Producer and Subscribing Consumer" type="JetRunConfigurationType" folderName="Kafka Axon Example">
<option name="MAIN_CLASS_NAME" value="org.axonframework.extensions.kafka.example.KafkaAxonExampleApplicationKt" />
<module name="axon-kafka-example" />
<module name="kafka-axon-example"/>
<option name="PROGRAM_PARAMETERS" value="--spring.profiles.active=tracking-producer,subscribing-consumer" />
<shortenClasspath name="NONE" />
<method v="2">
Expand Down
40 changes: 30 additions & 10 deletions kafka-axon-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,26 @@ Please run:
docker-compose -f ./kafka-axon-example/docker-compose.yaml up -d
```

This will start [Zookeeper](https://zookeeper.apache.org/), [Kafka](https://github.com/wurstmeister/kafka-docker),
[KafkaCat](https://github.com/edenhill/kafkacat), [Kafka Rest](https://github.com/nodefluent/kafka-rest) and [Kafka Rest UI](https://github.com/nodefluent/kafka-rest-ui).
KafkaCat can be used to investigate the setup, whereas the UI (accessed through localhost:8000, user `admin` and password `admin`) provides visualization of the internals.
This will start [Zookeeper](https://zookeeper.apache.org/), [Kafka](https://github.com/wurstmeister/kafka-docker),
[KafkaCat](https://github.com/edenhill/kafkacat), [Kafka Rest](https://github.com/nodefluent/kafka-rest)
and [Kafka Rest UI](https://github.com/nodefluent/kafka-rest-ui).
KafkaCat can be used to investigate the setup, whereas the UI (accessed through localhost:8000, user `admin` and
password `admin`) provides visualization of the internals.

Now build the application by running:
If you use IntelliJ the run configuration from ./run can be used, otherwise build the application using:

```bash
mvn clean package -f ./kafka-axon-example
```

### Running example application

You can start the application by running `java -jar ./kafka-axon-example/target/axon-kafka-example.jar`.

From a Kafka Message Source perspective, there are several options you have, as both consumption and production of
You can start the application by running `java -jar ./kafka-axon-example/target/kafka-axon-example.jar`.

From a Kafka Message Source perspective, there are several options you have, as both consumption and production of
event messages can be Subscribing or Streaming (aka push or pull).
Thus, the application can run in six different modes due to the possibility to define a producer
and consumer event processing mode.
and consumer event processing mode.
At this stage the following profiles can be used:

* `subscribing-producer`
Expand All @@ -41,7 +43,25 @@ At this stage the following profiles can be used:
* `subscribing-consumer`
* `tracking-consumer`
* `pooled-streaming-consumer`

* `cloud-events`

If not specified, a `subscribing` producer and `tracking` consumer will be used.
If `cloud-events` is not used, the format on the wire will be Axon Framework specific, using the
[DefaultKafkaMessageConverter.java](https://github.com/AxonFramework/extension-kafka/blob/master/kafka/src/main/java/org/axonframework/extensions/kafka/eventhandling/DefaultKafkaMessageConverter.java)
To activate these modes, please use Spring profiles in the run configuration like so:
`--spring.profiles.active=tracking-producer,subscribing-consumer`
`--spring.profiles.active=tracking-producer,subscribing-consumer`

### Checking the format on the wire

To check the format on the wire, including the headers you can get inside the Kafka container with:

```bash
docker exec -it kafka-axon-example_kafka_1 bash
```

You can use the `kafka-console-consumer.sh` script located in the Kafka container. The folder is located in a path
similar to `/opt/kafka_2.13-2.8.1/bin`. To consume all events from the default topic and also print the headers use:

```bash
./kafka-console-consumer.sh --topic Axon.Events --from-beginning --bootstrap-server localhost:9092 --property print.headers=true
```
4 changes: 2 additions & 2 deletions kafka-axon-example/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2021. Axon Framework
~ Copyright (c) 2010-2022. Axon Framework
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,7 @@
<version>4.6.0-SNAPSHOT</version>
</parent>

<artifactId>axon-kafka-example</artifactId>
<artifactId>kafka-axon-example</artifactId>
<version>4.6.0-SNAPSHOT</version>

<name>Axon Framework Kafka Extension - Spring Boot Example</name>
Expand Down
Loading

0 comments on commit a12b98b

Please sign in to comment.