Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is Pulsar Schema in java

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

What is Pulsar Schema in java? In general, people's understanding of Schema may stay at the conceptual level, but relatively little is known about the use of Schema in Pulsar. Today I will talk to you about how to use Schemar.

Basic concepts of Pulsar Schema

Schema is defined on topic.

The update strategy for Schema is defined in the namespace.

The following picture is an example of schema JSON format

Field description nameSchema name (found to be the same as topic name) typeSchema type, commonly used JSON format, other details see official document schemaSchema data is a sequence of 8-bit unsigned bytes and schema type specific, this attribute may be the internal use of schemaDefinition specific business data structure properties to store user-defined attributes

Generation of two Schema

Generate schema on Topic in three ways

1 producer producer

2 consumer messengers

3 manage API

There is no schema on topic by default. Whoever accesses Topic first in the above three ways will be the first version according to his / her schema structure.

Three JAVA management API

1 establish a connection

PulsarAdmin admin = PulsarAdmin.builder () .serviceHttpUrl (url) .build ()

Schemas schemas=admin.schemas (); / / get the schemas management object

2 View schmea

Specify all versions of schema on topic

List allSchemaInfo=schemas.getAllSchemas ("topic name")

Specify the latest version of schema on topic

SchemaInfo snedschemaInfo=schemas.getSchemaInfo ("topic name")

3 delete schmea

Schemas.deleteSchema ("topic name")

4 create schema

Schemas.createSchema ("topic name", schemaInfo)

About the Generation of schemaInfo object

1) you can use the RecordSchemaBuilder type

RecordSchemaBuilder recordSchemaBuilder = SchemaBuilder.record ("schemaName")

RecordSchemaBuilder.field ("ww") .type (SchemaType.INT32)

SchemaInfo schemaInfo = recordSchemaBuilder.build (SchemaType.JSON)

2) you can also use Schema

SchemaInfo schemaInfo=Schema.JSON (UserModel.class) .getSchemaInfo ()

Four schema update policies

Set schema policy method

Namespaces namespaces=admin.namespaces ()

Namespaces.setSchemaAutoUpdateCompatibilityStrategy (Namespace name, SchemaAutoUpdateCompatibilityStrategy. Attributes)

Whether to force schema validation

Namespaces.setSchemaValidationEnforced (Namespace name, false)

Suppose you have a theme with three scenarios (V1, V2, and V3). V1 is the oldest and V3 is the latest.

Property description checks which schemaFull schema V3 and V2 are backward and forward compatible (default policy) the latest versions of FullTransitive schemas V3, V2 and V1 are backward and forward compatible with all previous versions of AlwaysCompatible can change the schema structure Different structures result in new versions all previous versions AutoUpdateDisabled disabled updating schema structure No Backward consumers using schema V3 can handle data written by producers using schema V3 or V2 the latest version of BackwardTransitive using schema V3 consumers can handle data written by producers using schema V3, V2 or V1. Consumers of all previous versions of Forward using schema V3 or V2 can handle data written by producers using schema V3. The latest version of ForwardTransitive using schema V3, V2 or V1 consumers can deal with producers using schema V3 prepared by the data all the previous version of the above is the use of Schemar introduction, detailed use of their own to know the specific essentials. If you want to read more related articles, you are welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report