davsclaus opened a new issue, #3326: URL: https://github.com/apache/camel-kamelets/issues/3326
A new action Kamelet, `protobuf-message-action`, that turns JSON into a Protobuf message from the text of a `.proto` schema, without classes generated by `protoc`. ## Why With `schemaRegistryVendor` and `schemaFormat: protobuf` (#3295), `kafka-sink` needs a Protobuf message object as the body, and JSON text fails with a `SerializationException`. A YAML user today has to build a `DynamicMessage` in code. The Kafka protobuf tests do this in Groovy from a hand-made `FileDescriptorProto` (`kafka/kafka-schema-registry-protobuf-route.yaml` and `kafka/kafka-batch-schema-registry-protobuf-route.yaml`), and the `kafka-sink` description says the message "a step before this sink must create in code". [CAMEL-27329](https://issues.apache.org/jira/browse/CAMEL-27329) (apache/camel#30550, merged for 4.24.0) adds the `schema` and `messageName` options to the protobuf data format. With them, the data format reads JSON or Protobuf binary data into a `DynamicMessage`, and writes a `DynamicMessage` or a `Map`. The `.proto` parser is in the new `camel-protobuf-schema`, which brings Kotlin and Guava (about 6 MB), so it stays out of `kafka-sink`. ## Proposal - `protobuf-message-action`: an `unmarshal` with `protobuf`, `contentTypeFormat: json`, `schema` and `messageName`. - Options: - `schema`: required. The text of the `.proto` file, or a resource such as `classpath:order.proto`, `file:order.proto` or an `http:` URL. A Confluent API registry serves the text of a schema at `/subjects/<subject>/versions/latest/schema`. - `messageName`: optional. The message type, such as `Order`, `shop.Order` or the nested `Order.Line`. By default it is the first message type of the schema. - Input: JSON text of the Protobuf JSON mapping. Output: a `DynamicMessage`, for `kafka-sink` with `schemaFormat: protobuf`, or any other step that takes a Protobuf message. - Dependencies: `camel:protobuf` and `camel:protobuf-schema`. Only users who add this action get the parser. - `kafka-sink` stays unchanged, apart from its description, which can point to this action in place of "create in code". - Description written to the `documenting.adoc` standard, and dataTypes `in: application/json`. ## Tests - Citrus tests that replace the Groovy in the two Kafka protobuf routes: JSON → `protobuf-message-action` → `kafka-sink` with Confluent (Redpanda) and Apicurio, read back with `kafka-source`. - The errors to check: an unknown `messageName`, and JSON with a field the schema does not have. - A #3190 upgrade note for the new Kamelet. Open question: whether to offer the other direction too, a `DynamicMessage` or Protobuf bytes back to JSON. `kafka-source` already gives Protobuf records as JSON text, so this is not needed for Kafka. _Claude Code on behalf of Claus Ibsen_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
