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
CREATEpermissions.참고Security authorization requires
CREATEpermissions to add schemas. With the default settings, you need thedeployerrole 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
schemacommand with the--upload=argument from the Data Grid command line interface (CLI).schema --upload=person.proto personInclude the Protobuf schema in the payload of a
POSTrequest with the REST API.POST/rest/v2/schemas/<schema_name>Use the generated
SerializationContextInitializerimplementation 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
SerializationContextInitializerimplementation and custom classes to the$RHDG_HOME/server/libdirectory.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_metadatacache or automatically distributed across the cluster.참고You must do this if you require Data Grid Server to perform any
application/x-protostreamtoapplication/x-java-objectconversions, 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);