hhkkxxx133 commented on a change in pull request #16513: URL: https://github.com/apache/flink/pull/16513#discussion_r695442766
########## File path: flink-end-to-end-tests/flink-glue-schema-registry-json-test/src/main/java/org/apache/flink/glue/schema/registry/test/json/GSRKinesisPubsubClient.java ########## @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.glue.schema.registry.test.json; + +import org.apache.flink.streaming.connectors.kinesis.testutils.KinesisPubsubClient; + +import com.amazonaws.services.schemaregistry.common.AWSDeserializerInput; +import com.amazonaws.services.schemaregistry.common.AWSSerializerInput; +import com.amazonaws.services.schemaregistry.common.configs.GlueSchemaRegistryConfiguration; +import com.amazonaws.services.schemaregistry.deserializers.GlueSchemaRegistryDeserializationFacade; +import com.amazonaws.services.schemaregistry.serializers.GlueSchemaRegistrySerializationFacade; +import com.amazonaws.services.schemaregistry.utils.AWSSchemaRegistryConstants; +import com.amazonaws.services.schemaregistry.utils.AvroRecordType; +import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; +import software.amazon.awssdk.services.glue.model.DataFormat; + +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; + +/** + * Simple client to publish and retrieve messages, using the AWS Kinesis SDK, Flink Kinesis + * Connectors and Glue Schema Registry classes. + */ +public class GSRKinesisPubsubClient { + private final KinesisPubsubClient client; + + public GSRKinesisPubsubClient(Properties properties) { + this.client = new KinesisPubsubClient(properties); + } + + public void sendMessage(String schema, String streamName, Object msg) { + UUID schemaVersionId = + createSerializationFacade() + .getOrRegisterSchemaVersion( + AWSSerializerInput.builder() + .schemaDefinition(schema) + .dataFormat(DataFormat.JSON.name()) + .schemaName(streamName) + .transportName(streamName) + .build()); + + client.sendMessage( + streamName, + createSerializationFacade().serialize(DataFormat.JSON, msg, schemaVersionId)); + } + + public List<Object> readAllMessages(String streamName) throws Exception { + return client.readAllMessages( + streamName, + bytes -> + createDeserializationFacade() + .deserialize( + AWSDeserializerInput.builder() + .buffer(ByteBuffer.wrap(bytes)) + .transportName(streamName) + .build())); + } + + public void createStream(String stream, int shards, Properties props) throws Exception { + client.createTopic(stream, shards, props); + } + + private Map<String, Object> getSerDeConfigs() { + Map<String, Object> configs = new HashMap(); + configs.put(AWSSchemaRegistryConstants.AWS_REGION, "ca-central-1"); + configs.put(AWSSchemaRegistryConstants.SCHEMA_AUTO_REGISTRATION_SETTING, true); + configs.put( + AWSSchemaRegistryConstants.AVRO_RECORD_TYPE, Review comment: Removed in the latest commit. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
