本文整理汇总了Java中com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient类的典型用法代码示例。如果您正苦于以下问题:Java SchemaRegistryClient类的具体用法?Java SchemaRegistryClient怎么用?Java SchemaRegistryClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SchemaRegistryClient类属于com.hortonworks.registries.schemaregistry.client包,在下文中一共展示了SchemaRegistryClient类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreate
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
/**
* Return true if the schema creation failed as expected
*/
private void testCreate(SchemaRegistryClient client) {
boolean failedAsExpected = false;
SchemaMetadata schemaMetadata = new SchemaMetadata.Builder(name).type(type).schemaGroup(group).
description("description").build();
try {
client.registerSchemaMetadata(schemaMetadata);
} catch (BadRequestException ex) {
Response resp = ex.getResponse();
Assert.assertEquals(test + " - http response unexpected", expectedHttpResponse.getStatusCode(), resp.getStatus());
CatalogResponse catalogResponse = SchemaRegistryClient.readCatalogResponse(resp.readEntity(String.class));
Assert.assertEquals(test + " - catalog response unexpected",
expectedCatalogResponse.getCode(), catalogResponse.getResponseCode());
failedAsExpected = true;
}
Assert.assertTrue(test + " - did not fail as expected", failedAsExpected);
}
示例2: testSanity
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
@Test
public void testSanity() throws Exception {
SchemaRegistryTestServerClientWrapper schemaRegistryTestServerClientWrapper = new SchemaRegistryTestServerClientWrapper(SCHEMA_REGISTRY_TEST_CONFIGURATION);
schemaRegistryTestServerClientWrapper.startTestServer();
SchemaRegistryClient schemaRegistryClient = schemaRegistryTestServerClientWrapper.getClient();
// registering schema metadata
SchemaMetadata schemaMetadata = new SchemaMetadata.Builder("foo").type("avro").build();
Long schemaId = schemaRegistryClient.registerSchemaMetadata(schemaMetadata);
Assert.assertNotNull(schemaId);
// registering a new schema
String schemaName = schemaMetadata.getName();
String schema1 = IOUtils.toString(LocalRegistryServerTest.class.getResourceAsStream("/schema-1.avsc"), "UTF-8");
SchemaIdVersion v1 = schemaRegistryClient.addSchemaVersion(schemaName, new SchemaVersion(schema1, "Initial version of the schema"));
schemaRegistryTestServerClientWrapper.stopTestServer();
}
示例3: createConfig
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
public static Map<String, Object> createConfig(String schemaRegistryUrl) {
Map<String, Object> config = new HashMap<>();
config.put(SchemaRegistryClient.Configuration.SCHEMA_REGISTRY_URL.name(), schemaRegistryUrl);
config.put(SchemaRegistryClient.Configuration.CLASSLOADER_CACHE_SIZE.name(), 10L);
config.put(SchemaRegistryClient.Configuration.CLASSLOADER_CACHE_EXPIRY_INTERVAL_SECS.name(), 5000L);
config.put(SchemaRegistryClient.Configuration.SCHEMA_VERSION_CACHE_SIZE.name(), 1000L);
config.put(SchemaRegistryClient.Configuration.SCHEMA_VERSION_CACHE_EXPIRY_INTERVAL_SECS.name(), 60 * 60 * 1000L);
return config;
}
示例4: main
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
String schemaRegistryUrl = System.getProperty(SchemaRegistryClient.Configuration.SCHEMA_REGISTRY_URL.name(), DEFAULT_SCHEMA_REG_URL);
Map<String, Object> config = createConfig(schemaRegistryUrl);
SampleSchemaRegistryClientApp sampleSchemaRegistryClientApp = new SampleSchemaRegistryClientApp(config);
sampleSchemaRegistryClientApp.runSchemaApis();
sampleSchemaRegistryClientApp.runCustomSerDesApi();
sampleSchemaRegistryClientApp.runAvroSerDesApis();
}
示例5: testHASanity
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
@Test
public void testHASanity() throws Exception {
SchemaRegistryTestServerClientWrapper followerServer = followerSchemaRegistryServer();
SchemaRegistryClient schemaRegistryClient = followerServer.getClient();
// registering schema metadata on follower, this should have been redirected to leader.
String schemaName = "foo";
SchemaMetadata schemaMetadata = new SchemaMetadata.Builder(schemaName).type("avro").build();
Long schemaId = schemaRegistryClient.registerSchemaMetadata(schemaMetadata);
Assert.assertNotNull(schemaId);
// registering a new schema on follower, this should have been redirected to leader.
String schema1 = IOUtils.toString(LocalRegistryServerTest.class.getResourceAsStream("/schema-1.avsc"), "UTF-8");
SchemaIdVersion v1 = schemaRegistryClient.addSchemaVersion(schemaName,
new SchemaVersion(schema1, "Initial version of the schema"));
// retrieve schema on leader as the schema data is stored in memory in leader. this data does not exist on
// followers as the storage is inmemory.
SchemaRegistryTestServerClientWrapper leaderServer = leaderSchemaRegistryServer();
int leaderPort = leaderServer.getLocalPort();
SchemaRegistryClient leaderClient = leaderServer.getClient();
SchemaMetadataInfo schemaMetadataInfo = leaderClient.getSchemaMetadataInfo(schemaName);
Assert.assertEquals(schemaMetadata, schemaMetadataInfo.getSchemaMetadata());
// stop the leader server
leaderServer.stopTestServer();
// get the new leader server and run operations.
SchemaRegistryTestServerClientWrapper newLeaderServer = leaderSchemaRegistryServer();
Assert.assertNotEquals(leaderPort, newLeaderServer.getLocalPort());
leaderClient = newLeaderServer.getClient();
String receivedSchema = leaderClient.getSchemaVersionInfo(new SchemaVersionKey(schemaName, v1.getVersion())).getSchemaText();
Assert.assertEquals(schema1, receivedSchema);
}
示例6: configure
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
@Override
public void configure(Map<String, ?> configs, boolean isKey) {
// ignoring the isKey since this class is expected to be used only as a value serializer for now, value being StreamlineEvent
avroSnapshotSerializer.init(configs);
schemaRegistryClient = new SchemaRegistryClient(configs);
String writerSchemaVersion = (String) configs.get("writer.schema.version");
if (writerSchemaVersion != null && !writerSchemaVersion.isEmpty()) {
this.writerSchemaVersion = Integer.parseInt(writerSchemaVersion);
} else {
this.writerSchemaVersion = null;
}
}
示例7: run
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
@Override
public void run(ReviewServiceConfig config, Environment environment) throws Exception {
SchemaRegistryClient schemaRegistryClient = new SchemaRegistryClient(createConfig(config.getSchemaRegistryUrl()));
environment.jersey().register(new ReviewServiceResource(schemaRegistryClient));
}
示例8: ReviewServiceResource
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
public ReviewServiceResource(SchemaRegistryClient schemaRegistryClient) {
this.schemaRegistryClient = schemaRegistryClient;
}
示例9: SampleSchemaRegistryClientApp
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
public SampleSchemaRegistryClientApp(Map<String, Object> config) {
this.config = config;
schemaRegistryClient = new SchemaRegistryClient(config);
}
示例10: getClient
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
public SchemaRegistryClient getClient() throws IOException {
return getClient(false);
}
示例11: testConfluentProduceRegistryConsume
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
@Test
public void testConfluentProduceRegistryConsume() throws Exception {
String configPath = new File(Resources.getResource("schema-registry-test.yaml").toURI()).getAbsolutePath();
LocalSchemaRegistryServer localSchemaRegistryServer = new LocalSchemaRegistryServer(configPath);
try {
localSchemaRegistryServer.start();
final String confluentUrl = String.format("http://localhost:%d/api/v1/confluent", localSchemaRegistryServer.getLocalPort());
final String registryUrl = String.format("http://localhost:%d/api/v1", localSchemaRegistryServer.getLocalPort());
Map<String, Object> confluentConfig = new HashMap<>();
confluentConfig.put(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, confluentUrl);
Map<String, Object> registryConfig = new HashMap<>();
registryConfig.put(SchemaRegistryClient.Configuration.SCHEMA_REGISTRY_URL.name(), registryUrl);
Schema schema = new Schema.Parser().parse(GENERIC_TEST_RECORD_SCHEMA);
GenericRecord record = new GenericRecordBuilder(schema).set("field1", "some value").set("field2", "some other value").build();
io.confluent.kafka.serializers.KafkaAvroSerializer kafkaAvroSerializer = new io.confluent.kafka.serializers.KafkaAvroSerializer();
kafkaAvroSerializer.configure(confluentConfig, false);
byte[] bytes = kafkaAvroSerializer.serialize("topic", record);
io.confluent.kafka.serializers.KafkaAvroDeserializer confluentKafkaAvroDeserializer = new io.confluent.kafka.serializers.KafkaAvroDeserializer();
confluentKafkaAvroDeserializer.configure(confluentConfig, false);
GenericRecord confluentResult = (GenericRecord) confluentKafkaAvroDeserializer.deserialize("topic", bytes);
LOG.info(confluentResult.toString());
KafkaAvroDeserializer kafkaAvroDeserializer = new KafkaAvroDeserializer();
kafkaAvroDeserializer.configure(registryConfig, false);
GenericRecord registryResult = (GenericRecord) kafkaAvroDeserializer.deserialize("topic", bytes);
LOG.info(registryResult.toString());
Assert.assertEquals(record, registryResult);
Assert.assertEquals(record, confluentResult);
Assert.assertEquals(registryResult, confluentResult);
} finally {
localSchemaRegistryServer.stop();
}
}
示例12: testRegistryProduceConfluentConsume
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
@Test
public void testRegistryProduceConfluentConsume() throws Exception {
String configPath = new File(Resources.getResource("schema-registry-test.yaml").toURI()).getAbsolutePath();
LocalSchemaRegistryServer localSchemaRegistryServer = new LocalSchemaRegistryServer(configPath);
try {
localSchemaRegistryServer.start();
final String confluentUrl = String.format("http://localhost:%d/api/v1/confluent", localSchemaRegistryServer.getLocalPort());
final String registryUrl = String.format("http://localhost:%d/api/v1", localSchemaRegistryServer.getLocalPort());
Map<String, Object> confluentConfig = new HashMap<>();
confluentConfig.put(AbstractKafkaAvroSerDeConfig.SCHEMA_REGISTRY_URL_CONFIG, confluentUrl);
Map<String, Object> registryConfig = new HashMap<>();
registryConfig.put(SchemaRegistryClient.Configuration.SCHEMA_REGISTRY_URL.name(), registryUrl);
registryConfig.put(SERDES_PROTOCOL_VERSION, SerDesProtocolHandlerRegistry.CONFLUENT_VERSION_PROTOCOL);
Schema schema = new Schema.Parser().parse(GENERIC_TEST_RECORD_SCHEMA);
GenericRecord record = new GenericRecordBuilder(schema).set("field1", "some value").set("field2", "some other value").build();
KafkaAvroSerializer kafkaAvroSerializer = new KafkaAvroSerializer();
kafkaAvroSerializer.configure(registryConfig, false);
byte[] bytes = kafkaAvroSerializer.serialize("topic", record);
KafkaAvroDeserializer kafkaAvroDeserializer = new KafkaAvroDeserializer();
kafkaAvroDeserializer.configure(registryConfig, false);
GenericRecord registryResult = (GenericRecord) kafkaAvroDeserializer.deserialize("topic", bytes);
LOG.info(registryResult.toString());
io.confluent.kafka.serializers.KafkaAvroDeserializer confluentKafkaAvroDeserializer = new io.confluent.kafka.serializers.KafkaAvroDeserializer();
confluentKafkaAvroDeserializer.configure(confluentConfig, false);
GenericRecord confluentResult = (GenericRecord) confluentKafkaAvroDeserializer.deserialize("topic", bytes);
LOG.info(confluentResult.toString());
Assert.assertEquals(record, registryResult);
Assert.assertEquals(record, confluentResult);
Assert.assertEquals(registryResult, confluentResult);
} finally {
localSchemaRegistryServer.stop();
}
}
示例13: createSchemaRegistryClient
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
private SchemaRegistryClient createSchemaRegistryClient() {
Map<String, ?> conf = Collections.singletonMap(SchemaRegistryClient.Configuration.SCHEMA_REGISTRY_URL.name(),
config.get("schemaRegistryUrl"));
return new SchemaRegistryClient(conf);
}
示例14: SchemaResource
import com.hortonworks.registries.schemaregistry.client.SchemaRegistryClient; //导入依赖的package包/类
public SchemaResource(SchemaRegistryClient schemaRegistryClient) {
this.schemaRegistryClient = schemaRegistryClient;
}