Connecting to a Kafka schema registry
If you're already using a schema registry, you can use App Connect to connect to a registry to retrieve schemas so that you can concentrate on the message transfer rather than the message's data infrastructure.
A schema defines the structure, including the metadata, of the messages that pass between Kafka producer and consumer applications. These messages often require complex decoding as they pass between applications and the metadata can occupy lots of space on the Kafka brokers. A schema makes encoding and decoding data more efficient because all the messages adhere to a predefined structure.
<MAGIC_BYTE><SCHEMA_ID><SERIALIZED AVRO/JSON DATA>
where:<MAGIC_BYTE>
is 0 by default<SCHEMA_ID>
represents the Schema ID (confluent) or Global ID (Apicurio) and is mapped to bytes 1 - 4.<SERIALIZED AVRO/JSON DATA>
represents the actual serialized AVRO or JSON data and is mapped to the 5th byte onwards.
App Connect provides you with a simple user interface to connect to a schema registry so that you can avoid the complexity of dealing with data serialization and decoding between Kafka producer and consumer applications.
Connecting to a Kafka schema registry
- Schema registry type
- Select the schema registry that you want to connect to. App Connect supports Apicurio and Confluent schema registries. This
field defaults to Confluent if you provide a schema registry API URL and do not specify a registry
type.Restriction: Apicurio registry version 2.x and the Event Streams schema registry are not supported.
- Schema registry REST API URL
- The REST API URL of the schema registry in the format
http[s]://<hostname|ip address>:<port>
. For example:https://192.168.0.1:9001
. - Schema registry username
- The username of the schema registry.
- Schema registry password
- The password of the schema registry.
- Schema registry CA certificate
- The certificate of the schema registry certificate authority (CA) in PEM format.
Consuming AVRO/JSON serialized messages
To consume messages from a specific schema registry, you need to use the Kafka new message event node. This enables you to pull in the specified registry so that you can map to it from an action node.
- From the App Connect Designer dashboard, click (or in earlier versions) to open the flow editor.
- Enter a name that identifies the purpose of your flow.
- In the Applications tab, select Kafka.
- Select the Kafka account using the schema registry that you want to work with and then click New message. The event node is added to the flow and you are prompted to select the Kafka topic you are listening for messages on.
- Select the Kafka topic that you want to work with.
- Click Select output schema. The Schema settings window is displayed and you are prompted to select the schema type.
- Select the schema type. The options available are AVRO or JSON.
- Select the subject name and the schema version.
- Click Apply.
Generating and sending AVRO/JSON serialized messages
Custom headers in Kafka actions are a set of
name:value
pairs that are associated with a Kafka message as it is published and then retrieved when the
message is retrieved. Kafka custom header properties enable you
to interact with a schema registry and add metadata to Kafka
messages, which can then be used during message processing. For example, the header properties can
carry information about the format of the data, such as the schema subject name.
To send a message based on a specific schema format, you need to use the Kafka send message action. The following method works for both event driven flows and flows for an API.
- In the App Connect Designer dashboard, create an event driven flow or a flow for an API.
- For the action node, select .
- Select the Kafka topic that you want to work with.
- Click the drop-down arrow in the *Payload field.
- You are prompted to select a schema format based on the schema registry you
logged in with. The following options are available:
- AVRO
- JSON
- You are then prompted to select the subject name of the schema and the version.
- Click Apply.
The schema is pulled and presented in the format you selected in Step 5. You can now compose a message in your chosen schema format.