This is an automated email from the ASF dual-hosted git repository.
oscerd 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 049d8503c Fix #3326: new protobuf-message-action Kamelet, JSON text to
a Protobuf message of a .proto schema (#3327)
049d8503c is described below
commit 049d8503cbc66ea41363137c13a1f015e063dfd7
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 21 22:19:17 2026 +0100
Fix #3326: new protobuf-message-action Kamelet, JSON text to a Protobuf
message of a .proto schema (#3327)
The Kamelet turns JSON text into a DynamicMessage with the schema and
messageName options of the protobuf
data format (CAMEL-27329), so kafka-sink with schemaFormat protobuf can be
used without code. It declares
camel:protobuf and camel:protobuf-schema; kafka-sink is unchanged apart
from its description.
The two Kafka protobuf test routes use it in place of the Groovy step, and
a new Protobuf test checks the
JSON mapping, a nested message type, a value of the wrong type and an
unknown messageName.
Claude-Session: https://claude.ai/code/session_016Y4dDmBDsSWV117kccuNf9
Co-authored-by: Claude Opus 5.5 <[email protected]>
---
.../camel-kamelets-catalog-sbom.json | 38 +++++++++-
docs/modules/ROOT/nav.adoc | 1 +
.../ROOT/partials/kafka-sink-description.adoc | 5 +-
kamelets/kafka-sink.kamelet.yaml | 2 +-
kamelets/protobuf-message-action.kamelet.yaml | 75 +++++++++++++++++++
.../main/resources/META-INF/kamelets-index.json | 12 +++-
.../resources/kamelets/kafka-sink.kamelet.yaml | 2 +-
.../kamelets/protobuf-message-action.kamelet.yaml | 75 +++++++++++++++++++
...kafka-batch-schema-registry-protobuf-route.yaml | 28 ++------
.../kafka-schema-registry-protobuf-route.yaml | 28 ++------
.../protobuf/protobuf-message-action-route.yaml | 83 ++++++++++++++++++++++
.../protobuf-message-action-unknown-route.yaml | 30 ++++++++
.../protobuf-message-action.citrus.it.yaml | 55 ++++++++++++++
13 files changed, 382 insertions(+), 52 deletions(-)
diff --git a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
index 95af223a7..b26b9c955 100644
--- a/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
+++ b/camel-kamelets-sbom/camel-kamelets-catalog-sbom.json
@@ -851,6 +851,11 @@
"type" : "library",
"name" : "protobuf-deserialize-action",
"version" : "4.24.0-SNAPSHOT"
+ }, {
+ "bom-ref" : "kamelet:protobuf-message-action",
+ "type" : "library",
+ "name" : "protobuf-message-action",
+ "version" : "4.24.0-SNAPSHOT"
}, {
"bom-ref" : "kamelet:protobuf-serialize-action",
"type" : "library",
@@ -2009,6 +2014,28 @@
"name" : "camel.apache.org/versioned-by",
"value" : "runtime"
} ]
+ }, {
+ "bom-ref" :
"pkg:maven/org.apache.camel/[email protected]",
+ "type" : "library",
+ "group" : "org.apache.camel",
+ "name" : "camel-protobuf-schema",
+ "version" : "4.24.0-SNAPSHOT",
+ "purl" :
"pkg:maven/org.apache.camel/[email protected]",
+ "properties" : [ {
+ "name" : "camel.apache.org/versioned-by",
+ "value" : "runtime"
+ } ]
+ }, {
+ "bom-ref" : "pkg:maven/org.apache.camel/[email protected]",
+ "type" : "library",
+ "group" : "org.apache.camel",
+ "name" : "camel-protobuf",
+ "version" : "4.24.0-SNAPSHOT",
+ "purl" : "pkg:maven/org.apache.camel/[email protected]",
+ "properties" : [ {
+ "name" : "camel.apache.org/versioned-by",
+ "value" : "runtime"
+ } ]
}, {
"bom-ref" : "pkg:maven/org.apache.camel/[email protected]",
"type" : "library",
@@ -2260,7 +2287,7 @@
} ],
"dependencies" : [ {
"ref" : "camel-kamelets-catalog",
- "dependsOn" : [ "kamelet:avro-deserialize-action",
"kamelet:avro-serialize-action", "kamelet:aws-bedrock-agent-runtime-sink",
"kamelet:aws-bedrock-agent-sink", "kamelet:aws-bedrock-text-sink",
"kamelet:aws-cloudtrail-source", "kamelet:aws-cloudwatch-sink",
"kamelet:aws-comprehend-sink", "kamelet:aws-ddb-sink",
"kamelet:aws-ddb-streams-source", "kamelet:aws-ec2-sink",
"kamelet:aws-eventbridge-sink", "kamelet:aws-kinesis-firehose-sink",
"kamelet:aws-kinesis-sink", "kamelet:aws-kinesis- [...]
+ "dependsOn" : [ "kamelet:avro-deserialize-action",
"kamelet:avro-serialize-action", "kamelet:aws-bedrock-agent-runtime-sink",
"kamelet:aws-bedrock-agent-sink", "kamelet:aws-bedrock-text-sink",
"kamelet:aws-cloudtrail-source", "kamelet:aws-cloudwatch-sink",
"kamelet:aws-comprehend-sink", "kamelet:aws-ddb-sink",
"kamelet:aws-ddb-streams-source", "kamelet:aws-ec2-sink",
"kamelet:aws-eventbridge-sink", "kamelet:aws-kinesis-firehose-sink",
"kamelet:aws-kinesis-sink", "kamelet:aws-kinesis- [...]
}, {
"ref" : "kamelet:avro-deserialize-action",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
@@ -2765,6 +2792,9 @@
}, {
"ref" : "kamelet:protobuf-deserialize-action",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
+ }, {
+ "ref" : "kamelet:protobuf-message-action",
+ "dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
}, {
"ref" : "kamelet:protobuf-serialize-action",
"dependsOn" : [
"pkg:maven/org.apache.camel/[email protected]",
"pkg:maven/org.apache.camel/[email protected]" ]
@@ -3167,6 +3197,12 @@
}, {
"ref" : "pkg:maven/org.apache.camel/[email protected]",
"dependsOn" : [ ]
+ }, {
+ "ref" : "pkg:maven/org.apache.camel/[email protected]",
+ "dependsOn" : [ ]
+ }, {
+ "ref" : "pkg:maven/org.apache.camel/[email protected]",
+ "dependsOn" : [ ]
}, {
"ref" : "pkg:maven/org.apache.camel/[email protected]",
"dependsOn" : [ ]
diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc
index fba0b35c9..112b5c9cd 100644
--- a/docs/modules/ROOT/nav.adoc
+++ b/docs/modules/ROOT/nav.adoc
@@ -167,6 +167,7 @@
* xref:pqc-signature-action.adoc[]
* xref:predicate-filter-action.adoc[]
* xref:protobuf-deserialize-action.adoc[]
+* xref:protobuf-message-action.adoc[]
* xref:protobuf-serialize-action.adoc[]
* xref:pulsar-sink.adoc[]
* xref:pulsar-source.adoc[]
diff --git a/docs/modules/ROOT/partials/kafka-sink-description.adoc
b/docs/modules/ROOT/partials/kafka-sink-description.adoc
index b46e4b0b7..70fc79ac0 100644
--- a/docs/modules/ROOT/partials/kafka-sink-description.adoc
+++ b/docs/modules/ROOT/partials/kafka-sink-description.adoc
@@ -23,8 +23,9 @@ To write the records with a schema kept in a schema registry,
set `schemaRegistr
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 `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
+`.proto` file or a `DynamicMessage`; JSON text fails. To send JSON text, put
+xref:protobuf-message-action.adoc[`protobuf-message-action`] before the sink:
it turns JSON text into a Protobuf
+message of the `.proto` schema you give, with no generated classes. 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"]
diff --git a/kamelets/kafka-sink.kamelet.yaml b/kamelets/kafka-sink.kamelet.yaml
index 8d0566d77..5d5bb77a9 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 `protobuf`, the body must
be a Protobuf message, such as an object o [...]
+ 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.
diff --git a/kamelets/protobuf-message-action.kamelet.yaml
b/kamelets/protobuf-message-action.kamelet.yaml
new file mode 100644
index 000000000..0488e02eb
--- /dev/null
+++ b/kamelets/protobuf-message-action.kamelet.yaml
@@ -0,0 +1,75 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: protobuf-message-action
+ annotations:
+ camel.apache.org/kamelet.support.level: "Stable"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "Actions"
+ camel.apache.org/kamelet.namespace: "Transformation"
+ labels:
+ camel.apache.org/kamelet.type: "action"
+ camel.apache.org/kamelet.verified: "true"
+spec:
+ definition:
+ title: "Protobuf Message Action"
+ description: |-
+ Turns each message, JSON text, into a Protobuf message object that
follows the `.proto` schema you give, with no classes generated by the Protobuf
compiler.
+
+ Use it before `kafka-sink` with `schemaRegistryVendor` and
`schemaFormat` `protobuf`, which needs a Protobuf message object as the body
and fails on JSON text. It also suits any other step that takes a Protobuf
message (a `com.google.protobuf.Message`). To get Protobuf binary data instead,
use `protobuf-serialize-action`.
+
+ Input: JSON text, or its bytes, of one JSON object in the Protobuf JSON
mapping: each field by its name in the schema or in lowerCamelCase, a 64-bit
number as a number or as text, and an enum value by its name. For a Map or a
Jackson `JsonNode`, put `json-serialize-action` before this action.
+
+ Output: the body is a `com.google.protobuf.DynamicMessage` of the
message type `messageName`. The headers are kept.
+
+ Good to know: a field of the JSON that the schema does not have is left
out, and a value of the wrong type fails the message. The schema is read once,
when the Kamelet starts, so a syntax error, an unknown `messageName` or an
import other than the well-known types of Google (such as
`google/protobuf/timestamp.proto`) fails at startup. This Kamelet brings the
`.proto` parser `camel-protobuf-schema`, with Kotlin and Guava (about 6 MB).
+ required:
+ - schema
+ type: object
+ properties:
+ schema:
+ title: Schema
+ description: "The Protobuf schema, in the `.proto` language: the text
of the file, or where to read it, such as `classpath:order.proto`,
`file:/etc/schemas/order.proto` or an `http:` URL. A schema registry with the
Confluent API gives the text of a schema at
`/subjects/<subject>/versions/latest/schema`."
+ type: string
+ example: 'syntax = "proto3"; message Order { int32 id = 1; string item
= 2; }'
+ messageName:
+ title: Message Name
+ description: "The message type of the schema to build, such as
`Order`, `shop.Order` (with the package) or the nested `Order.Line`. When it is
not set, the first message type of the schema."
+ type: string
+ example: "shop.Order"
+ dataTypes:
+ in:
+ headers: {}
+ out:
+ headers: {}
+ dependencies:
+ - "camel:kamelet"
+ - "camel:protobuf"
+ - "camel:protobuf-schema"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ - unmarshal:
+ protobuf:
+ contentTypeFormat: json
+ schema: "{{schema}}"
+ messageName: "{{messageName:}}"
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 38192f1cc..32afd0f08 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
@@ -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"
@@ -1679,6 +1679,16 @@
"group" : "Actions",
"namespace" : "Transformation",
"provider" : "Apache Software Foundation"
+ }, {
+ "name" : "protobuf-message-action",
+ "type" : "action",
+ "supportLevel" : "Stable",
+ "title" : "Protobuf Message Action",
+ "summary" : "Turns each message, JSON text, into a Protobuf message object
that follows the `.proto` schema you give, with no classes generated by the
Protobuf compiler.",
+ "description" : "Turns each message, JSON text, into a Protobuf message
object that follows the `.proto` schema you give, with no classes generated by
the Protobuf compiler.\n\nUse it before `kafka-sink` with
`schemaRegistryVendor` and `schemaFormat` `protobuf`, which needs a Protobuf
message object as the body and fails on JSON text. It also suits any other step
that takes a Protobuf message (a `com.google.protobuf.Message`). To get
Protobuf binary data instead, use `protobuf-serial [...]
+ "group" : "Actions",
+ "namespace" : "Transformation",
+ "provider" : "Apache Software Foundation"
}, {
"name" : "protobuf-serialize-action",
"type" : "action",
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 8d0566d77..5d5bb77a9 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 `protobuf`, the body must
be a Protobuf message, such as an object o [...]
+ 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.
diff --git
a/library/camel-kamelets/src/main/resources/kamelets/protobuf-message-action.kamelet.yaml
b/library/camel-kamelets/src/main/resources/kamelets/protobuf-message-action.kamelet.yaml
new file mode 100644
index 000000000..0488e02eb
--- /dev/null
+++
b/library/camel-kamelets/src/main/resources/kamelets/protobuf-message-action.kamelet.yaml
@@ -0,0 +1,75 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+apiVersion: camel.apache.org/v1
+kind: Kamelet
+metadata:
+ name: protobuf-message-action
+ annotations:
+ camel.apache.org/kamelet.support.level: "Stable"
+ camel.apache.org/catalog.version: "4.24.0-SNAPSHOT"
+ camel.apache.org/kamelet.icon:
"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+CjxzdmcKICAgeG1sbnM6ZGM9Imh0dHA6Ly9wdXJsLm9yZy9kYy9lbGVtZW50cy8xLjEvIgogICB4bWxuczpjYz0iaHR0cDovL2NyZWF0aXZlY29tbW9ucy5vcmcvbnMjIgogICB4bWxuczpyZGY9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkvMDIvMjItcmRmLXN5bnRheC1ucyMiCiAgIHhtbG5zOnN2Zz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIKICAgeG1sbnM6c29kaXBvZGk9Imh0dHA6Ly9zb2RpcG
[...]
+ camel.apache.org/provider: "Apache Software Foundation"
+ camel.apache.org/kamelet.group: "Actions"
+ camel.apache.org/kamelet.namespace: "Transformation"
+ labels:
+ camel.apache.org/kamelet.type: "action"
+ camel.apache.org/kamelet.verified: "true"
+spec:
+ definition:
+ title: "Protobuf Message Action"
+ description: |-
+ Turns each message, JSON text, into a Protobuf message object that
follows the `.proto` schema you give, with no classes generated by the Protobuf
compiler.
+
+ Use it before `kafka-sink` with `schemaRegistryVendor` and
`schemaFormat` `protobuf`, which needs a Protobuf message object as the body
and fails on JSON text. It also suits any other step that takes a Protobuf
message (a `com.google.protobuf.Message`). To get Protobuf binary data instead,
use `protobuf-serialize-action`.
+
+ Input: JSON text, or its bytes, of one JSON object in the Protobuf JSON
mapping: each field by its name in the schema or in lowerCamelCase, a 64-bit
number as a number or as text, and an enum value by its name. For a Map or a
Jackson `JsonNode`, put `json-serialize-action` before this action.
+
+ Output: the body is a `com.google.protobuf.DynamicMessage` of the
message type `messageName`. The headers are kept.
+
+ Good to know: a field of the JSON that the schema does not have is left
out, and a value of the wrong type fails the message. The schema is read once,
when the Kamelet starts, so a syntax error, an unknown `messageName` or an
import other than the well-known types of Google (such as
`google/protobuf/timestamp.proto`) fails at startup. This Kamelet brings the
`.proto` parser `camel-protobuf-schema`, with Kotlin and Guava (about 6 MB).
+ required:
+ - schema
+ type: object
+ properties:
+ schema:
+ title: Schema
+ description: "The Protobuf schema, in the `.proto` language: the text
of the file, or where to read it, such as `classpath:order.proto`,
`file:/etc/schemas/order.proto` or an `http:` URL. A schema registry with the
Confluent API gives the text of a schema at
`/subjects/<subject>/versions/latest/schema`."
+ type: string
+ example: 'syntax = "proto3"; message Order { int32 id = 1; string item
= 2; }'
+ messageName:
+ title: Message Name
+ description: "The message type of the schema to build, such as
`Order`, `shop.Order` (with the package) or the nested `Order.Line`. When it is
not set, the first message type of the schema."
+ type: string
+ example: "shop.Order"
+ dataTypes:
+ in:
+ headers: {}
+ out:
+ headers: {}
+ dependencies:
+ - "camel:kamelet"
+ - "camel:protobuf"
+ - "camel:protobuf-schema"
+ template:
+ from:
+ uri: kamelet:source
+ steps:
+ - unmarshal:
+ protobuf:
+ contentTypeFormat: json
+ schema: "{{schema}}"
+ messageName: "{{messageName:}}"
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
index 69a703b12..1c59bc1b1 100644
---
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
@@ -26,29 +26,11 @@
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()
+ # protobuf-message-action builds the Protobuf message of the schema
Order from the JSON text
+ - to:
+ uri: "kamelet:protobuf-message-action"
+ parameters:
+ schema: 'syntax = "proto3"; message Order { int32 id = 1; string
item = 2; }'
- to:
uri: "kamelet:kafka-sink"
parameters:
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
index 428e9372c..b0b1e5d2e 100644
---
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
@@ -25,29 +25,11 @@
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()
+ # protobuf-message-action builds the Protobuf message of the schema
Order from the JSON text
+ - to:
+ uri: "kamelet:protobuf-message-action"
+ parameters:
+ schema: 'syntax = "proto3"; message Order { int32 id = 1; string
item = 2; }'
- to:
uri: "kamelet:kafka-sink"
parameters:
diff --git
a/tests/camel-kamelets-itest/src/test/resources/protobuf/protobuf-message-action-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/protobuf/protobuf-message-action-route.yaml
new file mode 100644
index 000000000..b42521987
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/protobuf/protobuf-message-action-route.yaml
@@ -0,0 +1,83 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+# JSON text in, a DynamicMessage of the schema out
+- route:
+ from:
+ uri: "timer:order"
+ parameters:
+ repeatCount: 1
+ steps:
+ # orderId: a field by its lowerCamelCase name, a 64-bit number as
text; item_count by its name in the schema;
+ # status: an enum by its name; at: a well-known type in its JSON form;
coupon: not in the schema
+ - setBody:
+ constant:
'{"orderId":"12345678901234","item_count":3,"status":"SHIPPED","line":{"qty":2},"at":"2026-11-21T10:00:00Z","coupon":"X"}'
+ - to:
+ uri: "kamelet:protobuf-message-action"
+ parameters:
+ messageName: "shop.Order"
+ schema: |
+ syntax = "proto3";
+ package shop;
+ import "google/protobuf/timestamp.proto";
+ message Order {
+ message Line { int32 qty = 1; }
+ enum Status { NEW = 0; SHIPPED = 1; }
+ int64 order_id = 1;
+ int32 item_count = 2;
+ Status status = 3;
+ Line line = 4;
+ google.protobuf.Timestamp at = 5;
+ }
+ - log: "Order ${body.getClass().getName()}:
${body.toString().replace('\n', ' ')}|"
+# The nested message type, from the bytes of the JSON text
+- route:
+ from:
+ uri: "timer:line"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '{"qty":5}'
+ - convertBodyTo:
+ type: "byte[]"
+ - to:
+ uri: "kamelet:protobuf-message-action"
+ parameters:
+ messageName: "Order.Line"
+ schema: 'message Order { message Line { optional int32 qty = 1;
}}'
+ - log: "Line ${body.getDescriptorForType().getFullName()}:
${body.toString().replace('\n', ' ')}|"
+# A value of the wrong type fails the message
+- route:
+ from:
+ uri: "timer:wrong"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '{"id":"abc"}'
+ - doTry:
+ steps:
+ - to:
+ uri: "kamelet:protobuf-message-action"
+ parameters:
+ schema: 'syntax = "proto3"; message Order { int32 id = 1;
}'
+ - log: "Accepted ${body}"
+ doCatch:
+ - exception:
+ - "java.lang.Exception"
+ steps:
+ - log: "Rejected ${exception.getClass().getName()}:
${exception.message}"
diff --git
a/tests/camel-kamelets-itest/src/test/resources/protobuf/protobuf-message-action-unknown-route.yaml
b/tests/camel-kamelets-itest/src/test/resources/protobuf/protobuf-message-action-unknown-route.yaml
new file mode 100644
index 000000000..1dc37572d
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/protobuf/protobuf-message-action-unknown-route.yaml
@@ -0,0 +1,30 @@
+# ---------------------------------------------------------------------------
+# 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.
+# ---------------------------------------------------------------------------
+# messageName is not a message type of the schema: the Kamelet fails at startup
+- route:
+ from:
+ uri: "timer:order"
+ parameters:
+ repeatCount: 1
+ steps:
+ - setBody:
+ constant: '{"id":1}'
+ - to:
+ uri: "kamelet:protobuf-message-action"
+ parameters:
+ messageName: "Invoice"
+ schema: 'syntax = "proto3"; message Order { int32 id = 1; }'
diff --git
a/tests/camel-kamelets-itest/src/test/resources/protobuf/protobuf-message-action.citrus.it.yaml
b/tests/camel-kamelets-itest/src/test/resources/protobuf/protobuf-message-action.citrus.it.yaml
new file mode 100644
index 000000000..cb699f391
--- /dev/null
+++
b/tests/camel-kamelets-itest/src/test/resources/protobuf/protobuf-message-action.citrus.it.yaml
@@ -0,0 +1,55 @@
+# ---------------------------------------------------------------------------
+# 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: protobuf-message-action-test
+actions:
+ - camel:
+ cli:
+ run:
+ integration:
+ file: "protobuf/protobuf-message-action-route.yaml"
+ # Every field of the schema is set, and the field that the schema does not
have is left out
+ - camel:
+ cli:
+ verify:
+ integration: "protobuf-message-action-route"
+ logMessage: "Order com.google.protobuf.DynamicMessage: order_id:
12345678901234 item_count: 3 status: SHIPPED line { qty: 2 } at { seconds:
1795255200 } |"
+ - camel:
+ cli:
+ verify:
+ integration: "protobuf-message-action-route"
+ logMessage: "Line Order.Line: qty: 5 |"
+ - camel:
+ cli:
+ verify:
+ integration: "protobuf-message-action-route"
+ logMessage: 'Rejected
com.google.protobuf.InvalidProtocolBufferException: Not an int32 value: "abc"'
+ # An unknown messageName fails when the Kamelet starts, so the integration
stops by itself
+ - camel:
+ cli:
+ run:
+ waitForRunningState: false
+ autoRemove: false
+ integration:
+ file: "protobuf/protobuf-message-action-unknown-route.yaml"
+ - camel:
+ cli:
+ verify:
+ integration: "protobuf-message-action-unknown-route"
+ phase: "Stopped"
+ logMessage: "The protobuf schema has no message type Invoice"