private String getIdForSchema(Schema schema) { if (!this.registrySchemaIds.containsKey(schema)) { try { String schemaId = this.overrideName.isPresent() ? this.registry.register(schema, this.overrideName.get()) : this.registry.register(schema); this.registrySchemaIds.put(schema, schemaId); } catch (SchemaRegistryException e) { throw Throwables.propagate(e); } } return this.registrySchemaIds.get(schema); }
public SchemaRegistryVersionWriter(KafkaAvroSchemaRegistry registry, Optional<String> overrideName, Optional<Schema> singleSchema) throws IOException { this.registry = registry; this.registrySchemaIds = Maps.newConcurrentMap(); this.overrideName = overrideName; this.schema = singleSchema; this.schemaIdLengthBytes = registry.getSchemaIdLengthByte(); if (this.schema.isPresent()) { try { this.schemaId = this.overrideName.isPresent() ? Optional .of(this.registry.register(this.schema.get(), this.overrideName.get())) : Optional.of(this.registry.register(this.schema.get())); } catch (SchemaRegistryException e) { throw Throwables.propagate(e); } } else { this.schemaId = Optional.absent(); } }
/** * Register a schema to the Kafka schema registry under the provided input name. This method will change the name * of the schema to the provided name. This is useful because certain services (like Gobblin kafka adaptor and * Camus) get the schema for a topic by querying for the latest schema with the topic name, requiring the topic * name and schema name to match for all topics. This method registers the schema to the schema registry in such a * way that any schema can be written to any topic. * * @param schema {@link org.apache.avro.Schema} to register. * @param overrideName Name of the schema when registerd to the schema registry. This name should match the name * of the topic where instances will be published. * @return schema ID of the registered schema. * @throws SchemaRegistryException if registration failed */ @Override public String register(Schema schema, String overrideName) throws SchemaRegistryException { return register(AvroUtils.switchName(schema, overrideName)); }
private static String getSchemaId(Properties properties, Schema schema) throws SchemaRegistryException { KafkaAvroSchemaRegistry kafkaAvroSchemaRegistry = (KafkaAvroSchemaRegistry) new KafkaAvroSchemaRegistryFactory().create(properties); return kafkaAvroSchemaRegistry.register(schema); }
Mockito.when(registry.register(Mockito.any(Schema.class))).thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation) Mockito.when(registry.register(Mockito.any(Schema.class), Mockito.anyString())).thenAnswer(new Answer<String>() { @Override public String answer(InvocationOnMock invocation)
private String getIdForSchema(Schema schema) { if (!this.registrySchemaIds.containsKey(schema)) { try { String schemaId = this.overrideName.isPresent() ? this.registry.register(schema, this.overrideName.get()) : this.registry.register(schema); this.registrySchemaIds.put(schema, schemaId); } catch (SchemaRegistryException e) { throw Throwables.propagate(e); } } return this.registrySchemaIds.get(schema); }
public SchemaRegistryVersionWriter(KafkaAvroSchemaRegistry registry, Optional<String> overrideName, Optional<Schema> singleSchema) throws IOException { this.registry = registry; this.registrySchemaIds = Maps.newConcurrentMap(); this.overrideName = overrideName; this.schema = singleSchema; this.schemaIdLengthBytes = registry.getSchemaIdLengthByte(); if (this.schema.isPresent()) { try { this.schemaId = this.overrideName.isPresent() ? Optional .of(this.registry.register(this.schema.get(), this.overrideName.get())) : Optional.of(this.registry.register(this.schema.get())); } catch (SchemaRegistryException e) { throw Throwables.propagate(e); } } else { this.schemaId = Optional.absent(); } }
/** * Register a schema to the Kafka schema registry under the provided input name. This method will change the name * of the schema to the provided name. This is useful because certain services (like Gobblin kafka adaptor and * Camus) get the schema for a topic by querying for the latest schema with the topic name, requiring the topic * name and schema name to match for all topics. This method registers the schema to the schema registry in such a * way that any schema can be written to any topic. * * @param schema {@link org.apache.avro.Schema} to register. * @param overrideName Name of the schema when registerd to the schema registry. This name should match the name * of the topic where instances will be published. * @return schema ID of the registered schema. * @throws SchemaRegistryException if registration failed */ @Override public String register(Schema schema, String overrideName) throws SchemaRegistryException { return register(AvroUtils.switchName(schema, overrideName)); }
private static String getSchemaId(Properties properties, Schema schema) throws SchemaRegistryException { KafkaAvroSchemaRegistry kafkaAvroSchemaRegistry = (KafkaAvroSchemaRegistry) new KafkaAvroSchemaRegistryFactory().create(properties); return kafkaAvroSchemaRegistry.register(schema); }