2.2.6. Data Grid Server への Protobuf スキーマの登録
Ickle クエリーを実行する場合、または application/x-protostream から application/json などの他のメディアタイプに変換する場合は、Data Grid Server に Protobuf スキーマを登録する必要があります。
前提条件
ProtoStream プロセッサーで Protobuf スキーマを生成します。
生成された Protobuf スキーマは、
target/<schemaFilePath>/ディレクトリーにあります。CREATE権限を持つユーザーを用意します。注記セキュリティー認可には、スキーマを追加するための
CREATE権限が必要です。デフォルト設定では、少なくともdeployerのロールが必要です。
手順
次のいずれかの方法で、Protobuf スキーマを Data Grid サーバーに追加します。
- 任意のブラウザーで Data Grid コンソールを開き、Schema タブを選択してから Add Protobuf schema を選択します。
Data Grid コマンドラインインターフェイス (CLI) から
--upload=引数を指定してschemaコマンドを使用します。schema --upload=person.proto personREST API を使用して、
POST要求のペイロードに Protobuf スキーマを含めます。POST/rest/v2/schemas/<schema_name>以下の例のように、Hot Rod クライアントで生成された
SerializationContextInitializer実装を使用して、Protobuf スキーマを登録します。/** * Register generated Protobuf schema with Data Grid Server. * This requires the RemoteCacheManager to be initialized. * * @param initializer The serialization context initializer for the schema. */ private void registerSchemas(SerializationContextInitializer initializer) { // Store schemas in the '___protobuf_metadata' cache to register them. // Using ProtobufMetadataManagerConstants might require the query dependency. final RemoteCache<String, String> protoMetadataCache = remoteCacheManager.getCache(ProtobufMetadataManagerConstants.PROTOBUF_METADATA_CACHE_NAME); // Add the generated schema to the cache. protoMetadataCache.put(initializer.getProtoFileName(), initializer.getProtoFile()); // Ensure the registered Protobuf schemas do not contain errors. // Throw an exception if errors exist. String errors = protoMetadataCache.get(ProtobufMetadataManagerConstants.ERRORS_KEY_SUFFIX); if (errors != null) { throw new IllegalStateException("Some Protobuf schema files contain errors: " + errors + "\nSchema :\n" + initializer.getProtoFileName()); } }SerializationContextInitializer実装およびカスタムクラスを持つ JAR ファイルを$RHDG_HOME/server/libディレクトリーに追加します。これを実行すると、Data Grid Server は起動時に Protobuf スキーマを登録します。ただし、スキーマは
___protobuf_metadataキャッシュに保存されたり、クラスター全体で自動的に分散されたりしないため、アーカイブを各サーバーインストールに追加する必要があります。注記Data Grid Server が
application/x-protostreamからapplication/x-java-objectへの変換を実施する必要がある場合、これを実行する必要があります。この場合、POJO 用の JAR ファイルも追加する必要があります。
次のステップ
以下の例のように、SerializationContextInitializer を Hot Rod クライアントに登録します。
ConfigurationBuilder remoteBuilder = new ConfigurationBuilder();
remoteBuilder.addServer().host(host).port(Integer.parseInt(port));
// Add your generated SerializationContextInitializer implementation.
LibraryInitalizer initializer = new LibraryInitalizerImpl();
remoteBuilder.addContextInitializer(initializer);