Chapter 2. Avro Deserialize Action
Deserialize payload to Avro.
2.1. Configuration Options Copy linkLink copied to clipboard!
The following table summarizes the configuration options available for the avro-deserialize-action Kamelet:
| Property | Name | Description | Type | Default | Example |
|---|---|---|---|---|---|
| schema | Schema | The Avro schema to use during serialization (as single-line, using JSON format) | string | {"type": "record", "namespace": "com.example", "name": "FullName", "fields": [{"name": "first", "type": "string"},{"name": "last", "type": "string"}]} | |
| validate | Validate | Indicates if the content must be validated against the schema | boolean | True |
* = Fields marked with an asterisk are mandatory.
2.2. Dependencies Copy linkLink copied to clipboard!
2.2.1. Quarkus dependencies Copy linkLink copied to clipboard!
<dependencies>
<dependency>
<groupId>org.apache.camel.kamelets</groupId>
<artifactId>camel-kamelets-utils</artifactId>
<version>4.8.5</version>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-avro-deserialize</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-jackson-avro</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-kamelet</artifactId>
</dependency>
</dependencies>
2.3. Usage Copy linkLink copied to clipboard!
2.3.1. Camel JBang usage Copy linkLink copied to clipboard!
2.3.1.1. Prerequisites for JBang Copy linkLink copied to clipboard!
- Install JBang.
You have executed the following command:
jbang app install camel@apache/camel
2.3.1.2. Running a route with JBang Copy linkLink copied to clipboard!
Suppose you have a file named route.yaml with this content:
- route:
from:
uri: "kamelet:timer-source"
parameters:
period: 10000
message: 'test'
steps:
- to:
uri: "kamelet:log-sink"
You can now run it directly through the following command.
camel run route.yaml
2.3.2. Knative Action Copy linkLink copied to clipboard!
You can use the avro-deserialize-action Kamelet as an intermediate step in a Knative binding.
avro-deserialize-action-binding.yaml
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: avro-deserialize-action-binding
spec:
source:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: timer-source
properties:
message: '{"first":"Ada","last":"Lovelace"}'
steps:
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: json-deserialize-action
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: avro-serialize-action
properties:
schema: "{\"type\": \"record\", \"namespace\": \"com.example\", \"name\": \"FullName\", \"fields\": [{\"name\": \"first\", \"type\": \"string\"},{\"name\": \"last\", \"type\": \"string\"}]}"
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: avro-deserialize-action
properties:
schema: "{\"type\": \"record\", \"namespace\": \"com.example\", \"name\": \"FullName\", \"fields\": [{\"name\": \"first\", \"type\": \"string\"},{\"name\": \"last\", \"type\": \"string\"}]}"
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: json-serialize-action
sink:
ref:
kind: Channel
apiVersion: messaging.knative.dev/v1
name: mychannel
2.3.3. Kafka Action Copy linkLink copied to clipboard!
You can use the avro-deserialize-action Kamelet as an intermediate step in a Kafka binding.
avro-deserialize-action-binding.yaml
apiVersion: camel.apache.org/v1
kind: Pipe
metadata:
name: avro-deserialize-action-binding
spec:
source:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: timer-source
properties:
message: '{"first":"Ada","last":"Lovelace"}'
steps:
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: json-deserialize-action
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: avro-serialize-action
properties:
schema: "{\"type\": \"record\", \"namespace\": \"com.example\", \"name\": \"FullName\", \"fields\": [{\"name\": \"first\", \"type\": \"string\"},{\"name\": \"last\", \"type\": \"string\"}]}"
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: avro-deserialize-action
properties:
schema: "{\"type\": \"record\", \"namespace\": \"com.example\", \"name\": \"FullName\", \"fields\": [{\"name\": \"first\", \"type\": \"string\"},{\"name\": \"last\", \"type\": \"string\"}]}"
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1
name: json-serialize-action
sink:
ref:
kind: KafkaTopic
apiVersion: kafka.strimzi.io/v1beta1
name: my-topic