This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-kamelets.git
The following commit(s) were added to refs/heads/main by this push:
new 5e7fca1b5 chore: Protobuf as a schema format of the Kafka Kamelets
(#3279) (#3295)
5e7fca1b5 is described below
commit 5e7fca1b575ba9994d2a0dca7e3494c936666738
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 21 13:55:48 2026 +0100
chore: Protobuf as a schema format of the Kafka Kamelets (#3279) (#3295)
* chore: default data types on the Messaging and Kafka Kamelets where the
body is fixed (#3117)
- pulsar-sink, mqtt5-sink: in default binary (application-octet-stream).
The body is turned into byte[] and Content-Type set to
application/octet-stream before sending; both send the same bytes as
before (the producers convert to byte[] themselves and send no headers),
but the message after the sink is byte[] instead of String.
- value-to-key-action, message-timestamp-router-action: out default json
(application-json). The body is byte[] instead of a stream
(InputStreamCache); Content-Type stays application/json.
- kafka-batch-source: the description says each List entry is a Camel
Exchange, read with getMessage().getBody(), not a message.
- Descriptions updated; the pulsar-sink, value-to-key-action and
message-timestamp-router-action Citrus tests expect [B and the new
Content-Type, and pulsar-sink checks its text through an X-Body header.
No default on the sources: a source Kamelet's out default runs only after
the whole consuming route, not before it, and fails the exchange there
when the route ends with a Map or a number. No default on the JMS,
spring-rabbitmq, nats, smpp and kafka sinks, kafka-source,
kafka-batch-source, smpp-source and the header-only Kafka actions.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* chore: kafka-batch-source can read records through a schema registry
(#3279)
kafka-batch-source gets the schema registry options of kafka-source:
schemaRegistryVendor, schemaRegistryUrl, schemaRegistryRegion,
schemaRegistryName and schemaFormat. As kafka-source does for one record, it
gives each value of the batch as JSON text: a JSON Schema value is
marshalled,
an Avro value is turned into its JSON text. It now depends on
camel:jackson3.
New Citrus tests write two records through the schema registry of Redpanda
with kafka-sink, with schemaFormat json and avro, and read them as one
batch.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* chore: the Kafka Kamelets can log in to the schema registry (#3279)
kafka-source, kafka-sink and kafka-batch-source pass the schema registry
login
options of camel-kafka (CAMEL-27256): schemaRegistryUsername and
schemaRegistryPassword for basic auth (the API key and secret of Confluent
Cloud), and schemaRegistryOauthTokenEndpoint, schemaRegistryOauthClientId,
schemaRegistryOauthClientSecret and schemaRegistryOauthScope for OAuth2
client
credentials. The secrets are marked as such and passed in RAW().
The descriptions say how each vendor logs in, and that Kafka only calls an
OAuth2 token endpoint listed in the JVM system property
org.apache.kafka.sasl.oauthbearer.allowed.urls, which also applies to the
existing saslAuthType OAUTH. A new Citrus test checks the basic auth login
that the registry receives.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* chore: Protobuf as a schema format of the Kafka Kamelets (#3279)
kafka-source, kafka-sink and kafka-batch-source accept schemaFormat
protobuf, which camel-kafka supports for confluent, apicurio and aws-glue.
The sources turn a Protobuf record into JSON text with the Protobuf JSON
mapping (JsonFormat of protobuf-java-util, which the Confluent and
Apicurio Protobuf serdes bring), as its toString() is the Protobuf text
format. JsonFormat is looked up only when a record is read: a camel:protobuf
dependency would put protobuf-java 4.35.1 on the Camel JBang classpath
before the Apicurio 3.3.4 serde, whose generated code needs 4.36.2, and the
consumer then stops without an error. No dependency is added.
The sink needs a Protobuf message object as the body; JSON text fails.
Citrus tests: Protobuf round trips through Redpanda (confluent), through
Apicurio Registry 3.3.4, and through kafka-batch-source.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
* chore: the Kafka partial pages describe the schema registry login
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../ROOT/partials/kafka-sink-description.adoc | 10 ++-
.../ROOT/partials/kafka-source-description.adoc | 15 ++--
kamelets/kafka-batch-source.kamelet.yaml | 19 ++++-
kamelets/kafka-sink.kamelet.yaml | 6 +-
kamelets/kafka-source.kamelet.yaml | 18 ++++-
.../main/resources/META-INF/kamelets-index.json | 6 +-
.../kamelets/kafka-batch-source.kamelet.yaml | 19 ++++-
.../resources/kamelets/kafka-sink.kamelet.yaml | 6 +-
.../resources/kamelets/kafka-source.kamelet.yaml | 18 ++++-
...h-schema-registry-protobuf-route.citrus.it.yaml | 82 ++++++++++++++++++++
...kafka-batch-schema-registry-protobuf-route.yaml | 86 +++++++++++++++++++++
...registry-apicurio-protobuf-route.citrus.it.yaml | 90 ++++++++++++++++++++++
...a-schema-registry-protobuf-route.citrus.it.yaml | 82 ++++++++++++++++++++
.../kafka-schema-registry-protobuf-route.yaml | 77 ++++++++++++++++++
14 files changed, 503 insertions(+), 31 deletions(-)
diff --git a/docs/modules/ROOT/partials/kafka-sink-description.adoc
b/docs/modules/ROOT/partials/kafka-sink-description.adoc
index 125a677cb..b46e4b0b7 100644
--- a/docs/modules/ROOT/partials/kafka-sink-description.adoc
+++ b/docs/modules/ROOT/partials/kafka-sink-description.adoc
@@ -22,15 +22,17 @@ To write the records with a schema kept in a schema
registry, set `schemaRegistr
`schemaFormat` (the default is `avro`). With `json`, the body must be JSON
text (or a Map); the Kamelet turns it into
an object, and the record is written with a JSON Schema made from it, which
accepts any JSON object. With `avro`,
`confluent` and `apicurio` write a text body as an Avro string, while
`aws-glue` needs an Avro record, which a step must
-create in code. With `azure`, also set `schemaGroup`. The sink registers the
+create in code. With `protobuf`, the body must be a Protobuf message, such as
an object of a class generated from the
+`.proto` file or a `DynamicMessage`, which a step must create in code; JSON
text fails. With `azure`, also set
+`schemaGroup`. The sink registers the
schema it makes, and does not check the message against a schema that is
already registered for the topic.
[width="100%",cols="1,1,3",options="header"]
|===
| `schemaRegistryVendor` | `schemaFormat` | Registry
-| `confluent` | `avro`, `json` | Confluent Schema Registry, and the registries
with the same API, such as the one of Redpanda and Karapace.
`schemaRegistryUrl` is the URL of the registry, such as `http://localhost:8081`.
-| `apicurio` | `avro` | Apicurio Registry 3.x. `schemaRegistryUrl` is the URL
of the registry API, such as `http://localhost:8080/apis/registry/v3`.
-| `aws-glue` | `avro`, `json` | AWS Glue Schema Registry. Set
`schemaRegistryRegion`, unless the environment has the region (such as
`AWS_REGION`), and `schemaRegistryName`, unless the registry is
`default-registry`. `schemaRegistryUrl` is not needed. The AWS credentials are
taken from the AWS default credentials chain.
+| `confluent` | `avro`, `json`, `protobuf` | Confluent Schema Registry, and
the registries with the same API, such as the one of Redpanda and Karapace.
`schemaRegistryUrl` is the URL of the registry, such as `http://localhost:8081`.
+| `apicurio` | `avro`, `protobuf` | Apicurio Registry 3.x. `schemaRegistryUrl`
is the URL of the registry API, such as
`http://localhost:8080/apis/registry/v3`.
+| `aws-glue` | `avro`, `json`, `protobuf` | AWS Glue Schema Registry. Set
`schemaRegistryRegion`, unless the environment has the region (such as
`AWS_REGION`), and `schemaRegistryName`, unless the registry is
`default-registry`. `schemaRegistryUrl` is not needed. The AWS credentials are
taken from the AWS default credentials chain.
| `azure` | `avro` | Azure Schema Registry of Event Hubs. `schemaRegistryUrl`
is the fully qualified name of the namespace, such as
`my-namespace.servicebus.windows.net`. The sink needs `schemaGroup`. The
credentials are taken by the Azure `DefaultAzureCredential`, such as from the
`AZURE_CLIENT_ID`, `AZURE_TENANT_ID` and `AZURE_CLIENT_SECRET` variables.
|===
diff --git a/docs/modules/ROOT/partials/kafka-source-description.adoc
b/docs/modules/ROOT/partials/kafka-source-description.adoc
index 17b9cca7b..f42671e36 100644
--- a/docs/modules/ROOT/partials/kafka-source-description.adoc
+++ b/docs/modules/ROOT/partials/kafka-source-description.adoc
@@ -67,16 +67,19 @@ keep working. The Kafka record headers are passed through
separately, controlled
=== Schema registry
When the records are written with a schema kept in a schema registry, set
`schemaRegistryVendor`, `schemaRegistryUrl`
-and, for JSON Schema, `schemaFormat: json` (the default is `avro`). The
Kamelet reads each value with its schema and
-turns it into JSON text, so the next step gets text as without a registry: an
Avro record becomes, for example,
-`{"id": 7, "item": "camel"}`.
+and, for JSON Schema or Protobuf, `schemaFormat: json` or `schemaFormat:
protobuf` (the default is `avro`). The
+Kamelet reads each value with its schema and turns it into JSON text, so the
next step gets text as without a registry:
+an Avro record becomes, for example, `{"id": 7, "item": "camel"}`. A Protobuf
record is turned into JSON by the
+Protobuf JSON mapping, such as `{"id":7,"item":"camel"}`: the names of the
fields are in lowerCamelCase (`orderNo`
+for `order_no`), 64-bit numbers are text, and the fields that have their
default value, such as 0 or empty text, are
+left out.
[width="100%",cols="1,1,3",options="header"]
|===
| `schemaRegistryVendor` | `schemaFormat` | Registry
-| `confluent` | `avro`, `json` | Confluent Schema Registry, and the registries
with the same API, such as the one of Redpanda and Karapace.
`schemaRegistryUrl` is the URL of the registry, such as `http://localhost:8081`.
-| `apicurio` | `avro` | Apicurio Registry 3.x. `schemaRegistryUrl` is the URL
of the registry API, such as `http://localhost:8080/apis/registry/v3`.
-| `aws-glue` | `avro`, `json` | AWS Glue Schema Registry. Set
`schemaRegistryRegion`, unless the environment has the region (such as
`AWS_REGION`), and `schemaRegistryName`, unless the registry is
`default-registry`. `schemaRegistryUrl` is not needed. The AWS credentials are
taken from the AWS default credentials chain.
+| `confluent` | `avro`, `json`, `protobuf` | Confluent Schema Registry, and
the registries with the same API, such as the one of Redpanda and Karapace.
`schemaRegistryUrl` is the URL of the registry, such as `http://localhost:8081`.
+| `apicurio` | `avro`, `protobuf` | Apicurio Registry 3.x. `schemaRegistryUrl`
is the URL of the registry API, such as
`http://localhost:8080/apis/registry/v3`.
+| `aws-glue` | `avro`, `json`, `protobuf` | AWS Glue Schema Registry. Set
`schemaRegistryRegion`, unless the environment has the region (such as
`AWS_REGION`), and `schemaRegistryName`, unless the registry is
`default-registry`. `schemaRegistryUrl` is not needed. The AWS credentials are
taken from the AWS default credentials chain.
| `azure` | `avro` | Azure Schema Registry of Event Hubs. `schemaRegistryUrl`
is the fully qualified name of the namespace, such as
`my-namespace.servicebus.windows.net`. The sink needs `schemaGroup`. The
credentials are taken by the Azure `DefaultAzureCredential`, such as from the
`AZURE_CLIENT_ID`, `AZURE_TENANT_ID` and `AZURE_CLIENT_SECRET` variables.
|===
diff --git a/kamelets/kafka-batch-source.kamelet.yaml
b/kamelets/kafka-batch-source.kamelet.yaml
index 67476ece7..2f24144ae 100644
--- a/kamelets/kafka-batch-source.kamelet.yaml
+++ b/kamelets/kafka-batch-source.kamelet.yaml
@@ -36,7 +36,7 @@ spec:
Use it to handle many records at once, for example to write them to a
database in one go, or to save the position in Kafka only once a whole batch
was handled. To handle one record at a time use `kafka-source`. When the
records are written with a schema kept in a schema registry, such as Confluent
Schema Registry, Redpanda or Apicurio Registry, set `schemaRegistryVendor`.
- Output: the body is a List with one entry per record, up to `batchSize`.
Each entry is a Camel `Exchange` for one record, not a message: a step reads
the value of the record, as text, with `getMessage().getBody()` on the entry,
such as `${body[0].getMessage().getBody()}`. With `schemaRegistryVendor`, each
value is read with its schema from the registry and is JSON text, such as
`{"id": 7, "item": "camel"}` for an Avro record; a record without a value (a
tombstone) gives an entry wi [...]
+ Output: the body is a List with one entry per record, up to `batchSize`.
Each entry is a Camel `Exchange` for one record, not a message: a step reads
the value of the record, as text, with `getMessage().getBody()` on the entry,
such as `${body[0].getMessage().getBody()}`. With `schemaRegistryVendor`, each
value is read with its schema from the registry and is JSON text, such as
`{"id": 7, "item": "camel"}` for an Avro record; a record without a value (a
tombstone) gives an entry wi [...]
Good to know: `saslAuthType` has no default and must be set; `NONE`
connects with no login and no TLS. To save the position in Kafka only once a
batch was handled, set `allowManualCommit` to true and `autoCommitEnable` to
false, and end the flow with `kafka-batch-manual-commit-action`. A new consumer
group starts at the newest records, unless `autoOffsetReset` is `earliest`.
Without `consumerGroup`, every start uses a new group, so the records sent
while the integration was stopped [...]
required:
@@ -202,9 +202,9 @@ spec:
type: string
schemaFormat:
title: Schema Format
- description: "The format of the record values in the schema registry:
`avro` or `json` (JSON Schema). With `apicurio` and `azure`, use `avro`. Only
used when `schemaRegistryVendor` is set."
+ description: "The format of the record values in the schema registry:
`avro`, `json` (JSON Schema) or `protobuf` (Protocol Buffers). With `apicurio`,
use `avro` or `protobuf`; with `azure`, use `avro`. Only used when
`schemaRegistryVendor` is set."
type: string
- enum: ["avro", "json"]
+ enum: ["avro", "json", "protobuf"]
default: avro
schemaRegistryUsername:
title: Schema Registry Username
@@ -358,6 +358,19 @@ spec:
expression:
simple:
expression:
"${exchangeProperty.kafkaEntry.getMessage().setBody(${body})}"
+ # A Protobuf message becomes the JSON of the
Protobuf JSON mapping, as in kafka-source
+ - expression:
+ simple:
+ expression: "'{{schemaFormat}}' ==
'protobuf' && ${body} != null && ${body} !is 'java.lang.String'"
+ steps:
+ - setBody:
+ expression:
+ simple:
+ expression:
"${bean:type:com.google.protobuf.util.JsonFormat?method=printer().omittingInsignificantWhitespace().print(${body})}"
+ - script:
+ expression:
+ simple:
+ expression:
"${exchangeProperty.kafkaEntry.getMessage().setBody(${body})}"
- expression:
simple:
expression: "${body} != null && ${body}
!is 'java.lang.String'"
diff --git a/kamelets/kafka-sink.kamelet.yaml b/kamelets/kafka-sink.kamelet.yaml
index e36528b7b..8d0566d77 100644
--- a/kamelets/kafka-sink.kamelet.yaml
+++ b/kamelets/kafka-sink.kamelet.yaml
@@ -36,7 +36,7 @@ spec:
Use it to publish events or data for other applications to read, such as
orders, sensor readings or changes from a database. To write the records with a
schema kept in a schema registry, such as Confluent Schema Registry, Redpanda
or Apicurio Registry, set `schemaRegistryVendor`.
- Input: the body becomes the value of the record, as text. Turn
structured data such as a Map into JSON text first, for example with
`json-serialize-action`. With `schemaRegistryVendor` and `schemaFormat` `json`,
the body must be JSON text (or a Map), and the record is written with a JSON
Schema; with `avro`, `confluent` and `apicurio` write a text body as an Avro
string, while `aws-glue` needs an Avro record. With `azure`, set `schemaGroup`.
The optional `key` header (or `kafka-key [...]
+ Input: the body becomes the value of the record, as text. Turn
structured data such as a Map into JSON text first, for example with
`json-serialize-action`. With `schemaRegistryVendor` and `schemaFormat` `json`,
the body must be JSON text (or a Map), and the record is written with a JSON
Schema; with `avro`, `confluent` and `apicurio` write a text body as an Avro
string, while `aws-glue` needs an Avro record; with `protobuf`, the body must
be a Protobuf message, such as an object o [...]
Output: the message is unchanged.
@@ -147,9 +147,9 @@ spec:
type: string
schemaFormat:
title: Schema Format
- description: "The format of the record values in the schema registry:
`avro` or `json` (JSON Schema). With `apicurio` and `azure`, use `avro`. Only
used when `schemaRegistryVendor` is set."
+ description: "The format of the record values in the schema registry:
`avro`, `json` (JSON Schema) or `protobuf` (Protocol Buffers). With `apicurio`,
use `avro` or `protobuf`; with `azure`, use `avro`. Only used when
`schemaRegistryVendor` is set."
type: string
- enum: ["avro", "json"]
+ enum: ["avro", "json", "protobuf"]
default: avro
schemaRegistryUsername:
title: Schema Registry Username
diff --git a/kamelets/kafka-source.kamelet.yaml
b/kamelets/kafka-source.kamelet.yaml
index 8eb113f8c..93a486c5d 100644
--- a/kamelets/kafka-source.kamelet.yaml
+++ b/kamelets/kafka-source.kamelet.yaml
@@ -36,7 +36,7 @@ spec:
Use it to react to events or data that other applications publish, such
as orders, sensor readings or changes from a database. To get many records in
one message use `kafka-batch-source`. When the records are written with a
schema kept in a schema registry, such as Confluent Schema Registry, Redpanda
or Apicurio Registry, set `schemaRegistryVendor`.
- Output: the body is the value of the record, as text. With
`schemaRegistryVendor`, the value is read with its schema from the registry and
the body is JSON text, such as `{"id": 7, "item": "camel"}` for an Avro record.
A record without a value (a tombstone) gives a message with no body. The
`kafka-topic`, `kafka-key`, `kafka-partition`, `kafka-offset` and
`kafka-timestamp` (in milliseconds since 1970) headers say where the record
came from. They are also set as `ce-kafkatopic`, `ce [...]
+ Output: the body is the value of the record, as text. With
`schemaRegistryVendor`, the value is read with its schema from the registry and
the body is JSON text, such as `{"id": 7, "item": "camel"}` for an Avro record.
A Protobuf record is turned into JSON by the Protobuf JSON mapping, such as
`{"id":7,"item":"camel"}`: the names of the fields are in lowerCamelCase
(`orderNo` for `order_no`), 64-bit numbers are text, and the fields that have
their default value, such as 0 or empty [...]
Good to know: `saslAuthType` has no default and must be set; `NONE`
connects with no login and no TLS. A new consumer group starts at the newest
records, unless `autoOffsetReset` is `earliest`. Without `consumerGroup`, every
start uses a new group, so the records sent while the integration was stopped
are skipped. With `schemaRegistryVendor`, the integration needs the serde jars
of the vendor, which Camel JBang downloads by itself; for `confluent` add the
Confluent Maven repository [...]
required:
@@ -182,9 +182,9 @@ spec:
type: string
schemaFormat:
title: Schema Format
- description: "The format of the record values in the schema registry:
`avro` or `json` (JSON Schema). With `apicurio` and `azure`, use `avro`. Only
used when `schemaRegistryVendor` is set."
+ description: "The format of the record values in the schema registry:
`avro`, `json` (JSON Schema) or `protobuf` (Protocol Buffers). With `apicurio`,
use `avro` or `protobuf`; with `azure`, use `avro`. Only used when
`schemaRegistryVendor` is set."
type: string
- enum: ["avro", "json"]
+ enum: ["avro", "json", "protobuf"]
default: avro
schemaRegistryUsername:
title: Schema Registry Username
@@ -379,6 +379,18 @@ spec:
library: Jackson
- convertBodyTo:
type: java.lang.String
+ # A Protobuf message (a DynamicMessage, or a generated class)
becomes the JSON of the Protobuf JSON
+ # mapping, as its toString() is the Protobuf text format, which
is not JSON. JsonFormat is in
+ # protobuf-java-util, which the Protobuf serdes of Confluent and
Apicurio bring; it is looked up only
+ # when a record is read, so that no other version of Protobuf is
put on the classpath first.
+ - expression:
+ simple:
+ expression: "'{{?schemaRegistryVendor}}' != '' &&
'{{schemaFormat}}' == 'protobuf' && ${body} != null && ${body} !is
'java.lang.String'"
+ steps:
+ - setBody:
+ expression:
+ simple:
+ expression:
"${bean:type:com.google.protobuf.util.JsonFormat?method=printer().omittingInsignificantWhitespace().print(${body})}"
- expression:
simple:
expression: "'{{?schemaRegistryVendor}}' != '' && ${body}
!= null && ${body} !is 'java.lang.String'"
diff --git
a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
index ecfffe956..0ca257d8d 100644
--- a/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
+++ b/library/camel-kamelets/src/main/resources/META-INF/kamelets-index.json
@@ -1305,7 +1305,7 @@
"supportLevel" : "Stable",
"title" : "Kafka Batch Source",
"summary" : "Receives records from one or more topics in Apache Kafka in
batches, as one message that holds a list of up to `batchSize` records.",
- "description" : "Receives records from one or more topics in Apache Kafka
in batches, as one message that holds a list of up to `batchSize`
records.\n\nUse it to handle many records at once, for example to write them to
a database in one go, or to save the position in Kafka only once a whole batch
was handled. To handle one record at a time use `kafka-source`. When the
records are written with a schema kept in a schema registry, such as Confluent
Schema Registry, Redpanda or Apicurio [...]
+ "description" : "Receives records from one or more topics in Apache Kafka
in batches, as one message that holds a list of up to `batchSize`
records.\n\nUse it to handle many records at once, for example to write them to
a database in one go, or to save the position in Kafka only once a whole batch
was handled. To handle one record at a time use `kafka-source`. When the
records are written with a schema kept in a schema registry, such as Confluent
Schema Registry, Redpanda or Apicurio [...]
"group" : "Kafka",
"namespace" : "Kafka",
"provider" : "Apache Software Foundation"
@@ -1325,7 +1325,7 @@
"supportLevel" : "Stable",
"title" : "Kafka Sink",
"summary" : "Sends each message as a record to a topic in Apache Kafka, or
in a Kafka-compatible service such as Amazon MSK, Confluent Cloud or Redpanda.",
- "description" : "Sends each message as a record to a topic in Apache
Kafka, or in a Kafka-compatible service such as Amazon MSK, Confluent Cloud or
Redpanda.\n\nUse it to publish events or data for other applications to read,
such as orders, sensor readings or changes from a database. To write the
records with a schema kept in a schema registry, such as Confluent Schema
Registry, Redpanda or Apicurio Registry, set `schemaRegistryVendor`.\n\nInput:
the body becomes the value of the re [...]
+ "description" : "Sends each message as a record to a topic in Apache
Kafka, or in a Kafka-compatible service such as Amazon MSK, Confluent Cloud or
Redpanda.\n\nUse it to publish events or data for other applications to read,
such as orders, sensor readings or changes from a database. To write the
records with a schema kept in a schema registry, such as Confluent Schema
Registry, Redpanda or Apicurio Registry, set `schemaRegistryVendor`.\n\nInput:
the body becomes the value of the re [...]
"group" : "Kafka",
"namespace" : "Kafka",
"provider" : "Apache Software Foundation"
@@ -1335,7 +1335,7 @@
"supportLevel" : "Stable",
"title" : "Kafka Source",
"summary" : "Receives each record from one or more topics in Apache Kafka,
or in a Kafka-compatible service such as Amazon MSK, Confluent Cloud or
Redpanda.",
- "description" : "Receives each record from one or more topics in Apache
Kafka, or in a Kafka-compatible service such as Amazon MSK, Confluent Cloud or
Redpanda.\n\nUse it to react to events or data that other applications publish,
such as orders, sensor readings or changes from a database. To get many records
in one message use `kafka-batch-source`. When the records are written with a
schema kept in a schema registry, such as Confluent Schema Registry, Redpanda
or Apicurio Registry, [...]
+ "description" : "Receives each record from one or more topics in Apache
Kafka, or in a Kafka-compatible service such as Amazon MSK, Confluent Cloud or
Redpanda.\n\nUse it to react to events or data that other applications publish,
such as orders, sensor readings or changes from a database. To get many records
in one message use `kafka-batch-source`. When the records are written with a
schema kept in a schema registry, such as Confluent Schema Registry, Redpanda
or Apicurio Registry, [...]
"group" : "Kafka",
"namespace" : "Kafka",
"provider" : "Apache Software Foundation"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/kafka-batch-source.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/kafka-batch-source.kamelet.yaml
index 67476ece7..2f24144ae 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/kafka-batch-source.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/kafka-batch-source.kamelet.yaml
@@ -36,7 +36,7 @@ spec:
Use it to handle many records at once, for example to write them to a
database in one go, or to save the position in Kafka only once a whole batch
was handled. To handle one record at a time use `kafka-source`. When the
records are written with a schema kept in a schema registry, such as Confluent
Schema Registry, Redpanda or Apicurio Registry, set `schemaRegistryVendor`.
- Output: the body is a List with one entry per record, up to `batchSize`.
Each entry is a Camel `Exchange` for one record, not a message: a step reads
the value of the record, as text, with `getMessage().getBody()` on the entry,
such as `${body[0].getMessage().getBody()}`. With `schemaRegistryVendor`, each
value is read with its schema from the registry and is JSON text, such as
`{"id": 7, "item": "camel"}` for an Avro record; a record without a value (a
tombstone) gives an entry wi [...]
+ Output: the body is a List with one entry per record, up to `batchSize`.
Each entry is a Camel `Exchange` for one record, not a message: a step reads
the value of the record, as text, with `getMessage().getBody()` on the entry,
such as `${body[0].getMessage().getBody()}`. With `schemaRegistryVendor`, each
value is read with its schema from the registry and is JSON text, such as
`{"id": 7, "item": "camel"}` for an Avro record; a record without a value (a
tombstone) gives an entry wi [...]
Good to know: `saslAuthType` has no default and must be set; `NONE`
connects with no login and no TLS. To save the position in Kafka only once a
batch was handled, set `allowManualCommit` to true and `autoCommitEnable` to
false, and end the flow with `kafka-batch-manual-commit-action`. A new consumer
group starts at the newest records, unless `autoOffsetReset` is `earliest`.
Without `consumerGroup`, every start uses a new group, so the records sent
while the integration was stopped [...]
required:
@@ -202,9 +202,9 @@ spec:
type: string
schemaFormat:
title: Schema Format
- description: "The format of the record values in the schema registry:
`avro` or `json` (JSON Schema). With `apicurio` and `azure`, use `avro`. Only
used when `schemaRegistryVendor` is set."
+ description: "The format of the record values in the schema registry:
`avro`, `json` (JSON Schema) or `protobuf` (Protocol Buffers). With `apicurio`,
use `avro` or `protobuf`; with `azure`, use `avro`. Only used when
`schemaRegistryVendor` is set."
type: string
- enum: ["avro", "json"]
+ enum: ["avro", "json", "protobuf"]
default: avro
schemaRegistryUsername:
title: Schema Registry Username
@@ -358,6 +358,19 @@ spec:
expression:
simple:
expression:
"${exchangeProperty.kafkaEntry.getMessage().setBody(${body})}"
+ # A Protobuf message becomes the JSON of the
Protobuf JSON mapping, as in kafka-source
+ - expression:
+ simple:
+ expression: "'{{schemaFormat}}' ==
'protobuf' && ${body} != null && ${body} !is 'java.lang.String'"
+ steps:
+ - setBody:
+ expression:
+ simple:
+ expression:
"${bean:type:com.google.protobuf.util.JsonFormat?method=printer().omittingInsignificantWhitespace().print(${body})}"
+ - script:
+ expression:
+ simple:
+ expression:
"${exchangeProperty.kafkaEntry.getMessage().setBody(${body})}"
- expression:
simple:
expression: "${body} != null && ${body}
!is 'java.lang.String'"
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/kafka-sink.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/kafka-sink.kamelet.yaml
index e36528b7b..8d0566d77 100644
--- a/library/camel-kamelets/src/main/resources/kamelets/kafka-sink.kamelet.yaml
+++ b/library/camel-kamelets/src/main/resources/kamelets/kafka-sink.kamelet.yaml
@@ -36,7 +36,7 @@ spec:
Use it to publish events or data for other applications to read, such as
orders, sensor readings or changes from a database. To write the records with a
schema kept in a schema registry, such as Confluent Schema Registry, Redpanda
or Apicurio Registry, set `schemaRegistryVendor`.
- Input: the body becomes the value of the record, as text. Turn
structured data such as a Map into JSON text first, for example with
`json-serialize-action`. With `schemaRegistryVendor` and `schemaFormat` `json`,
the body must be JSON text (or a Map), and the record is written with a JSON
Schema; with `avro`, `confluent` and `apicurio` write a text body as an Avro
string, while `aws-glue` needs an Avro record. With `azure`, set `schemaGroup`.
The optional `key` header (or `kafka-key [...]
+ Input: the body becomes the value of the record, as text. Turn
structured data such as a Map into JSON text first, for example with
`json-serialize-action`. With `schemaRegistryVendor` and `schemaFormat` `json`,
the body must be JSON text (or a Map), and the record is written with a JSON
Schema; with `avro`, `confluent` and `apicurio` write a text body as an Avro
string, while `aws-glue` needs an Avro record; with `protobuf`, the body must
be a Protobuf message, such as an object o [...]
Output: the message is unchanged.
@@ -147,9 +147,9 @@ spec:
type: string
schemaFormat:
title: Schema Format
- description: "The format of the record values in the schema registry:
`avro` or `json` (JSON Schema). With `apicurio` and `azure`, use `avro`. Only
used when `schemaRegistryVendor` is set."
+ description: "The format of the record values in the schema registry:
`avro`, `json` (JSON Schema) or `protobuf` (Protocol Buffers). With `apicurio`,
use `avro` or `protobuf`; with `azure`, use `avro`. Only used when
`schemaRegistryVendor` is set."
type: string
- enum: ["avro", "json"]
+ enum: ["avro", "json", "protobuf"]
default: avro
schemaRegistryUsername:
title: Schema Registry Username
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/kafka-source.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/kafka-source.kamelet.yaml
index 8eb113f8c..93a486c5d 100644
---
a/library/camel-kamelets/src/main/resources/kamelets/kafka-source.kamelet.yaml
+++
b/library/camel-kamelets/src/main/resources/kamelets/kafka-source.kamelet.yaml
@@ -36,7 +36,7 @@ spec:
Use it to react to events or data that other applications publish, such
as orders, sensor readings or changes from a database. To get many records in
one message use `kafka-batch-source`. When the records are written with a
schema kept in a schema registry, such as Confluent Schema Registry, Redpanda
or Apicurio Registry, set `schemaRegistryVendor`.
- Output: the body is the value of the record, as text. With
`schemaRegistryVendor`, the value is read with its schema from the registry and
the body is JSON text, such as `{"id": 7, "item": "camel"}` for an Avro record.
A record without a value (a tombstone) gives a message with no body. The
`kafka-topic`, `kafka-key`, `kafka-partition`, `kafka-offset` and
`kafka-timestamp` (in milliseconds since 1970) headers say where the record
came from. They are also set as `ce-kafkatopic`, `ce [...]
+ Output: the body is the value of the record, as text. With
`schemaRegistryVendor`, the value is read with its schema from the registry and
the body is JSON text, such as `{"id": 7, "item": "camel"}` for an Avro record.
A Protobuf record is turned into JSON by the Protobuf JSON mapping, such as
`{"id":7,"item":"camel"}`: the names of the fields are in lowerCamelCase
(`orderNo` for `order_no`), 64-bit numbers are text, and the fields that have
their default value, such as 0 or empty [...]
Good to know: `saslAuthType` has no default and must be set; `NONE`
connects with no login and no TLS. A new consumer group starts at the newest
records, unless `autoOffsetReset` is `earliest`. Without `consumerGroup`, every
start uses a new group, so the records sent while the integration was stopped
are skipped. With `schemaRegistryVendor`, the integration needs the serde jars
of the vendor, which Camel JBang downloads by itself; for `confluent` add the
Confluent Maven repository [...]
required:
@@ -182,9 +182,9 @@ spec:
type: string
schemaFormat:
title: Schema Format
- description: "The format of the record values in the schema registry:
`avro` or `json` (JSON Schema). With `apicurio` and `azure`, use `avro`. Only
used when `schemaRegistryVendor` is set."
+ description: "The format of the record values in the schema registry:
`avro`, `json` (JSON Schema) or `protobuf` (Protocol Buffers). With `apicurio`,
use `avro` or `protobuf`; with `azure`, use `avro`. Only used when
`schemaRegistryVendor` is set."
type: string
- enum: ["avro", "json"]
+ enum: ["avro", "json", "protobuf"]
default: avro
schemaRegistryUsername:
title: Schema Registry Username
@@ -379,6 +379,18 @@ spec:
library: Jackson
- convertBodyTo:
type: java.lang.String
+ # A Protobuf message (a DynamicMessage, or a generated class)
becomes the JSON of the Protobuf JSON
+ # mapping, as its toString() is the Protobuf text format, which
is not JSON. JsonFormat is in
+ # protobuf-java-util, which the Protobuf serdes of Confluent and
Apicurio bring; it is looked up only
+ # when a record is read, so that no other version of Protobuf is
put on the classpath first.
+ - expression:
+ simple:
+ expression: "'{{?schemaRegistryVendor}}' != '' &&
'{{schemaFormat}}' == 'protobuf' && ${body} != null && ${body} !is
'java.lang.String'"
+ steps:
+ - setBody:
+ expression:
+ simple:
+ expression:
"${bean:type:com.google.protobuf.util.JsonFormat?method=printer().omittingInsignificantWhitespace().print(${body})}"
- expression:
simple:
expression: "'{{?schemaRegistryVendor}}' != '' && ${body}
!= null && ${body} !is 'java.lang.String'"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-batch-schema-registry-protobuf-route.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-batch-schema-registry-protobuf-route.citrus.it.yaml
new file mode 100644
index 000000000..6db5a768e
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-batch-schema-registry-protobuf-route.citrus.it.yaml
@@ -0,0 +1,82 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+# ---------------------------------------------------------------------------
+
+
+name: kafka-batch-schema-registry-protobuf-route-test
+variables:
+ - name: "kafka.topic"
+ value: "batch-registry-protobuf"
+actions:
+ # Redpanda has a schema registry with the Confluent API
+ - testcontainers:
+ start:
+ redpanda: {}
+
+ # The Confluent serde jars are in the Confluent Maven repository
+ - camel:
+ cli:
+ run:
+ args:
+ - "--repos=confluent"
+ integration:
+ file: "kafka/kafka-batch-schema-registry-protobuf-route.yaml"
+ systemProperties:
+ properties:
+ - name: kafka.topic
+ value: "${kafka.topic}"
+ - name: kafka.bootstrapServers
+ value: "${CITRUS_TESTCONTAINERS_REDPANDA_BOOTSTRAP_SERVERS}"
+ - name: kafka.schemaRegistryUrl
+ value:
"${CITRUS_TESTCONTAINERS_REDPANDA_SCHEMA_REGISTRY_ADDRESS}"
+ - name: http.sink.url
+ value: "http://localhost:${kafka.sink.server.port}/result"
+
+ # One message for the two records, each Protobuf value read with its schema
and given as JSON text
+ - http:
+ server: "kafkaSinkServer"
+ receiveRequest:
+ POST:
+ path: "/result"
+ type: "plaintext"
+ headers:
+ - name: "X-Batch-Size"
+ value: "2"
+ - name: "X-Entry-Type"
+ value: "java.lang.String"
+ body:
+ data: '{"id":1,"item":"camel"}|{"id":2,"item":"camel"}'
+ - http:
+ server: "kafkaSinkServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
+
+ # The records were written with a Protobuf schema in the registry
+ - http:
+ client:
"${CITRUS_TESTCONTAINERS_REDPANDA_SCHEMA_REGISTRY_ADDRESS}/subjects/${kafka.topic}-value/versions/latest"
+ sendRequest:
+ GET: {}
+ - http:
+ client:
"${CITRUS_TESTCONTAINERS_REDPANDA_SCHEMA_REGISTRY_ADDRESS}/subjects/${kafka.topic}-value/versions/latest"
+ receiveResponse:
+ response:
+ status: 200
+ body:
+ data: |
+
{"subject":"${kafka.topic}-value","version":"@ignore@","id":"@ignore@","schemaType":"PROTOBUF","schema":"@contains('message
Order')@"}
diff --git
a/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-batch-schema-registry-protobuf-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-batch-schema-registry-protobuf-route.yaml
new file mode 100644
index 000000000..69a703b12
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-batch-schema-registry-protobuf-route.yaml
@@ -0,0 +1,86 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+# ---------------------------------------------------------------------------
+
+# kafka-sink writes two Protobuf messages through the schema registry, with
schemaFormat protobuf
+- route:
+ from:
+ uri: "timer:records"
+ parameters:
+ period: "200"
+ repeatCount: 2
+ includeMetadata: true
+ steps:
+ - setBody:
+ simple:
'{"id":${exchangeProperty.CamelTimerCounter},"item":"camel"}'
+ # A Protobuf message of the schema Order (id, item), built from the
JSON text. The schema is made in code,
+ # so that no Protobuf compiler or vendor class is needed
+ - setBody:
+ groovy: |
+ import com.google.protobuf.DescriptorProtos.DescriptorProto
+ import com.google.protobuf.DescriptorProtos.FieldDescriptorProto
+ import com.google.protobuf.DescriptorProtos.FileDescriptorProto
+ import com.google.protobuf.Descriptors.FileDescriptor
+ import com.google.protobuf.DynamicMessage
+ import com.google.protobuf.util.JsonFormat
+ def field = { String name, int number, FieldDescriptorProto.Type
type ->
+
FieldDescriptorProto.newBuilder().setName(name).setNumber(number).setType(type)
+
.setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL).build()
+ }
+ def file =
FileDescriptorProto.newBuilder().setName("order.proto").setSyntax("proto3")
+
.addMessageType(DescriptorProto.newBuilder().setName("Order")
+ .addField(field("id", 1,
FieldDescriptorProto.Type.TYPE_INT32))
+ .addField(field("item", 2,
FieldDescriptorProto.Type.TYPE_STRING)))
+ .build()
+ def order = DynamicMessage.newBuilder(
+ FileDescriptor.buildFrom(file, new
FileDescriptor[0]).findMessageTypeByName("Order"))
+ JsonFormat.parser().merge(body, order)
+ order.build()
+ - to:
+ uri: "kamelet:kafka-sink"
+ parameters:
+ bootstrapServers: '{{kafka.bootstrapServers}}'
+ saslAuthType: NONE
+ topic: '{{kafka.topic}}'
+ schemaRegistryVendor: confluent
+ schemaRegistryUrl: '{{kafka.schemaRegistryUrl}}'
+ schemaFormat: protobuf
+# kafka-batch-source reads them as one batch, with their schema from the
registry
+- route:
+ from:
+ uri: "kamelet:kafka-batch-source"
+ parameters:
+ bootstrapServers: '{{kafka.bootstrapServers}}'
+ saslAuthType: NONE
+ topic: '{{kafka.topic}}'
+ autoOffsetReset: earliest
+ consumerGroup: 'batch-registry-protobuf'
+ batchSize: 2
+ batchingIntervalMs: 3000
+ schemaRegistryVendor: confluent
+ schemaRegistryUrl: '{{kafka.schemaRegistryUrl}}'
+ schemaFormat: protobuf
+ steps:
+ - setHeader:
+ name: X-Batch-Size
+ simple: "${body.size()}"
+ - setHeader:
+ name: X-Entry-Type
+ simple: "${body[0].getMessage().getBody().getClass().getName()}"
+ - setBody:
+ simple:
"${body[0].getMessage().getBody()}|${body[1].getMessage().getBody()}"
+ - to:
+ uri: "{{http.sink.url}}"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-schema-registry-apicurio-protobuf-route.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-schema-registry-apicurio-protobuf-route.citrus.it.yaml
new file mode 100644
index 000000000..80a7d03f2
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-schema-registry-apicurio-protobuf-route.citrus.it.yaml
@@ -0,0 +1,90 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+# ---------------------------------------------------------------------------
+
+
+name: kafka-schema-registry-apicurio-protobuf-route-test
+variables:
+ - name: "kafka.topic"
+ value: "apicurio-protobuf"
+actions:
+ # Redpanda for Kafka, and Apicurio Registry 3.x as the schema registry
+ - testcontainers:
+ start:
+ redpanda: {}
+ - testcontainers:
+ start:
+ container:
+ name: "apicurio"
+ image: "apicurio/apicurio-registry:3.3.4"
+ autoRemove: true
+ startUpTimeout: 120
+ exposedPorts:
+ - 8080
+ waitFor:
+ logMessage: '.*Listening on.*'
+
+ - camel:
+ cli:
+ run:
+ integration:
+ file: "kafka/kafka-schema-registry-protobuf-route.yaml"
+ systemProperties:
+ properties:
+ - name: kafka.topic
+ value: "${kafka.topic}"
+ - name: kafka.bootstrapServers
+ value: "${CITRUS_TESTCONTAINERS_REDPANDA_BOOTSTRAP_SERVERS}"
+ - name: kafka.schemaRegistryVendor
+ value: "apicurio"
+ - name: kafka.schemaRegistryUrl
+ value:
"http://${CITRUS_TESTCONTAINERS_APICURIO_HOST}:${CITRUS_TESTCONTAINERS_APICURIO_PORT}/apis/registry/v3"
+ - name: http.sink.url
+ value: "http://localhost:${kafka.sink.server.port}/result"
+
+ # kafka-sink writes the Protobuf message, kafka-source reads it and gives it
as JSON text
+ - http:
+ server: "kafkaSinkServer"
+ receiveRequest:
+ POST:
+ path: "/result"
+ type: "plaintext"
+ headers:
+ - name: "X-Body-Type"
+ value: "java.lang.String"
+ body:
+ data: '{"id":1,"item":"camel"}'
+ - http:
+ server: "kafkaSinkServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
+
+ # The record was written with a Protobuf schema, registered in the default
group of the registry
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_APICURIO_HOST}:${CITRUS_TESTCONTAINERS_APICURIO_PORT}/apis/registry/v3/groups/default/artifacts/${kafka.topic}-value"
+ sendRequest:
+ GET: {}
+ - http:
+ client:
"http://${CITRUS_TESTCONTAINERS_APICURIO_HOST}:${CITRUS_TESTCONTAINERS_APICURIO_PORT}/apis/registry/v3/groups/default/artifacts/${kafka.topic}-value"
+ receiveResponse:
+ response:
+ status: 200
+ body:
+ data: |
+
{"owner":"@ignore@","createdOn":"@ignore@","modifiedBy":"@ignore@","modifiedOn":"@ignore@","artifactType":"PROTOBUF","artifactId":"${kafka.topic}-value"}
diff --git
a/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-schema-registry-protobuf-route.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-schema-registry-protobuf-route.citrus.it.yaml
new file mode 100644
index 000000000..0bad4600d
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-schema-registry-protobuf-route.citrus.it.yaml
@@ -0,0 +1,82 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+# ---------------------------------------------------------------------------
+
+
+name: kafka-schema-registry-protobuf-route-test
+variables:
+ - name: "kafka.topic"
+ value: "registry-protobuf"
+actions:
+ # Redpanda has a schema registry with the Confluent API
+ - testcontainers:
+ start:
+ redpanda: {}
+
+ # The Confluent serde jars are in the Confluent Maven repository
+ - camel:
+ cli:
+ run:
+ args:
+ - "--repos=confluent"
+ integration:
+ file: "kafka/kafka-schema-registry-protobuf-route.yaml"
+ systemProperties:
+ properties:
+ - name: kafka.topic
+ value: "${kafka.topic}"
+ - name: kafka.bootstrapServers
+ value: "${CITRUS_TESTCONTAINERS_REDPANDA_BOOTSTRAP_SERVERS}"
+ - name: kafka.schemaRegistryVendor
+ value: "confluent"
+ - name: kafka.schemaRegistryUrl
+ value:
"${CITRUS_TESTCONTAINERS_REDPANDA_SCHEMA_REGISTRY_ADDRESS}"
+ - name: http.sink.url
+ value: "http://localhost:${kafka.sink.server.port}/result"
+
+ # kafka-sink writes the Protobuf message, kafka-source reads it and gives it
as JSON text
+ - http:
+ server: "kafkaSinkServer"
+ receiveRequest:
+ POST:
+ path: "/result"
+ type: "plaintext"
+ headers:
+ - name: "X-Body-Type"
+ value: "java.lang.String"
+ body:
+ data: '{"id":1,"item":"camel"}'
+ - http:
+ server: "kafkaSinkServer"
+ sendResponse:
+ response:
+ status: 200
+ reasonPhrase: "OK"
+ version: "HTTP/1.1"
+
+ # The record was written with a Protobuf schema in the registry
+ - http:
+ client:
"${CITRUS_TESTCONTAINERS_REDPANDA_SCHEMA_REGISTRY_ADDRESS}/subjects/${kafka.topic}-value/versions/latest"
+ sendRequest:
+ GET: {}
+ - http:
+ client:
"${CITRUS_TESTCONTAINERS_REDPANDA_SCHEMA_REGISTRY_ADDRESS}/subjects/${kafka.topic}-value/versions/latest"
+ receiveResponse:
+ response:
+ status: 200
+ body:
+ data: |
+
{"subject":"${kafka.topic}-value","version":"@ignore@","id":"@ignore@","schemaType":"PROTOBUF","schema":"@contains('message
Order')@"}
diff --git
a/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-schema-registry-protobuf-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-schema-registry-protobuf-route.yaml
new file mode 100644
index 000000000..428e9372c
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/kafka/kafka-schema-registry-protobuf-route.yaml
@@ -0,0 +1,77 @@
+# ---------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+# ---------------------------------------------------------------------------
+
+# kafka-sink writes a Protobuf message through the schema registry, with
schemaFormat protobuf
+- route:
+ from:
+ uri: "timer:records"
+ parameters:
+ period: "1000"
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '{"id":1,"item":"camel"}'
+ # A Protobuf message of the schema Order (id, item), built from the
JSON text. The schema is made in code,
+ # so that no Protobuf compiler or vendor class is needed
+ - setBody:
+ groovy: |
+ import com.google.protobuf.DescriptorProtos.DescriptorProto
+ import com.google.protobuf.DescriptorProtos.FieldDescriptorProto
+ import com.google.protobuf.DescriptorProtos.FileDescriptorProto
+ import com.google.protobuf.Descriptors.FileDescriptor
+ import com.google.protobuf.DynamicMessage
+ import com.google.protobuf.util.JsonFormat
+ def field = { String name, int number, FieldDescriptorProto.Type
type ->
+
FieldDescriptorProto.newBuilder().setName(name).setNumber(number).setType(type)
+
.setLabel(FieldDescriptorProto.Label.LABEL_OPTIONAL).build()
+ }
+ def file =
FileDescriptorProto.newBuilder().setName("order.proto").setSyntax("proto3")
+
.addMessageType(DescriptorProto.newBuilder().setName("Order")
+ .addField(field("id", 1,
FieldDescriptorProto.Type.TYPE_INT32))
+ .addField(field("item", 2,
FieldDescriptorProto.Type.TYPE_STRING)))
+ .build()
+ def order = DynamicMessage.newBuilder(
+ FileDescriptor.buildFrom(file, new
FileDescriptor[0]).findMessageTypeByName("Order"))
+ JsonFormat.parser().merge(body, order)
+ order.build()
+ - to:
+ uri: "kamelet:kafka-sink"
+ parameters:
+ bootstrapServers: '{{kafka.bootstrapServers}}'
+ saslAuthType: NONE
+ topic: '{{kafka.topic}}'
+ schemaRegistryVendor: '{{kafka.schemaRegistryVendor}}'
+ schemaRegistryUrl: '{{kafka.schemaRegistryUrl}}'
+ schemaFormat: protobuf
+# kafka-source reads it with its schema from the registry
+- route:
+ from:
+ uri: "kamelet:kafka-source"
+ parameters:
+ bootstrapServers: '{{kafka.bootstrapServers}}'
+ saslAuthType: NONE
+ topic: '{{kafka.topic}}'
+ autoOffsetReset: earliest
+ schemaRegistryVendor: '{{kafka.schemaRegistryVendor}}'
+ schemaRegistryUrl: '{{kafka.schemaRegistryUrl}}'
+ schemaFormat: protobuf
+ steps:
+ - setHeader:
+ name: X-Body-Type
+ simple: "${body.getClass().getName()}"
+ - to:
+ uri: "{{http.sink.url}}"