Kamelet Catalog

protobuf message action Protobuf Message Action

Provided by: "Apache Software Foundation"

Support Level for this Kamelet is: "Stable"

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).

Configuration Options

The following table summarizes the configuration options available for the protobuf-message-action Kamelet:

Property Name Description Type Default Example

schema

Schema

Required 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.

string

syntax = "proto3"; message Order { int32 id = 1; string item = 2; }

messageName

Message Name

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.

string

shop.Order

Dependencies

At runtime, the protobuf-message-action Kamelet relies upon the presence of the following dependencies:

  • camel:kamelet

  • camel:protobuf

  • camel:protobuf-schema

Camel JBang usage

Prerequisites

  • You’ve installed JBang.

  • You have executed the following command:

jbang app install camel@apache/camel

Supposing 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:protobuf-message-action"
            parameters:
            .
            .
            .
        - to:
            uri: "kamelet:log-sink"

You can now run it directly through the following command

camel run route.yaml