2.2.7. Registering Protobuf schemas with Data Grid Server


Register Protobuf schemas with Data Grid Server to perform Ickle queries or convert from application/x-protostream to other media types such as application/json.

Prerequisites

  • Generate Protobuf schema with the ProtoStream processor.

    You can find generated Protobuf schema in the target/<schemaFilePath>/ directory.

  • Have a user with CREATE permissions.

    참고

    Security authorization requires CREATE permissions to add schemas. With the default settings, you need the deployer role at minimum.

Procedure

Add Protobuf schema to Data Grid Server in one of the following ways:

  • Open the Data Grid Console in any browser, select the Schema tab and then Add Protobuf schema.
  • Use the schema command with the --upload= argument from the Data Grid command line interface (CLI).

    schema --upload=person.proto person
  • Include the Protobuf schema in the payload of a POST request with the REST API.

    POST/rest/v2/schemas/<schema_name>
  • Use the generated SerializationContextInitializer implementation with a Hot Rod client to register the Protobuf schema, as in the following example:

    /**
     * Register generated Protobuf schema with Data Grid Server.
     * This requires the RemoteCacheManager to be initialized.
     *
     * @param schema The schema to be registered. Can be a {@link GeneratedSchema } or a programmatic one.
     * See {@link SerializationContextInitialiser}
     */
    private void registerSchemas(Schema schema) {
      RemoteSchemasAdmin schemas = remoteCacheManager.administration().schemas();
      schemas.create(schema);
    
      // Ensure the registered Protobuf schemas do not contain errors.
      // Throw an exception if errors exist.
      Optional<String> error = schemas.retrieveError(schema.getName())
      if (error.isPresent()) {
        throw new IllegalStateException("The schema contains an error: " + error.get() + "\nSchema :\n" + schema.getName());
      }
    }
  • Add a JAR file with the SerializationContextInitializer implementation and custom classes to the $RHDG_HOME/server/lib directory.

    When you do this, Data Grid Server registers your Protobuf schema at startup. However, you must add the archive to each server installation because the schema are not saved in the ___protobuf_metadata cache or automatically distributed across the cluster.

    참고

    You must do this if you require Data Grid Server to perform any application/x-protostream to application/x-java-object conversions, in which case you must also add any JAR files for your POJOs.

Next steps

Register the SerializationContextInitializer with your Hot Rod clients, as in the following example:

ConfigurationBuilder remoteBuilder = new ConfigurationBuilder();
remoteBuilder.addServer().host(host).port(Integer.parseInt(port));

// Add your generated SerializationContextInitializer implementation.
LibraryInitalizer initializer = new LibraryInitalizerImpl();
remoteBuilder.addContextInitializer(initializer);
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 문서 정보

Legal Notice

Theme

© 2026 Red Hat
맨 위로 이동