Java Code Examples for org.apache.kafka.common.serialization.Serde#configure()

The following examples show how to use org.apache.kafka.common.serialization.Serde#configure() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyValueSerdeResolver.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
private Serde<?> getKeySerde(String keySerdeString) {
	Serde<?> keySerde;
	try {
		if (StringUtils.hasText(keySerdeString)) {
			keySerde = Utils.newInstance(keySerdeString, Serde.class);
		}
		else {
			keySerde = getFallbackSerde("default.key.serde");
		}
		keySerde.configure(this.streamConfigGlobalProperties, true);

	}
	catch (ClassNotFoundException ex) {
		throw new IllegalStateException("Serde class not found: ", ex);
	}
	return keySerde;
}
 
Example 2
Source File: KeyValueSerdeResolver.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
private Serde<?> getKeySerde(String keySerdeString, ResolvableType resolvableType) {
	Serde<?> keySerde = null;
	try {
		if (StringUtils.hasText(keySerdeString)) {
			keySerde = Utils.newInstance(keySerdeString, Serde.class);
		}
		else {
			if (resolvableType != null &&
					(isResolvalbeKafkaStreamsType(resolvableType) || isResolvableKStreamArrayType(resolvableType))) {
				ResolvableType generic = resolvableType.isArray() ? resolvableType.getComponentType().getGeneric(0) : resolvableType.getGeneric(0);
				Serde<?> fallbackSerde = getFallbackSerde("default.key.serde");
				keySerde = getSerde(generic, fallbackSerde);
			}
			if (keySerde == null) {
				keySerde = Serdes.ByteArray();
			}
		}
		keySerde.configure(this.streamConfigGlobalProperties, true);
	}
	catch (ClassNotFoundException ex) {
		throw new IllegalStateException("Serde class not found: ", ex);
	}
	return keySerde;
}
 
Example 3
Source File: KeyValueSerdeResolver.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private Serde<?> getValueSerde(String valueSerdeString, ResolvableType resolvableType)
		throws ClassNotFoundException {
	Serde<?> valueSerde = null;
	if (StringUtils.hasText(valueSerdeString)) {
		valueSerde = Utils.newInstance(valueSerdeString, Serde.class);
	}
	else {

		if (resolvableType != null && ((isResolvalbeKafkaStreamsType(resolvableType)) ||
				(isResolvableKStreamArrayType(resolvableType)))) {
			Serde<?> fallbackSerde = getFallbackSerde("default.value.serde");
			ResolvableType generic = resolvableType.isArray() ? resolvableType.getComponentType().getGeneric(1) : resolvableType.getGeneric(1);
			valueSerde = getSerde(generic, fallbackSerde);
		}
		if (valueSerde == null) {

			valueSerde = Serdes.ByteArray();
		}
	}
	valueSerde.configure(streamConfigGlobalProperties, false);
	return valueSerde;
}
 
Example 4
Source File: ClientUtils.java    From kafka-graphs with Apache License 2.0 5 votes vote down vote up
public static <T> Serde<T> getSerde(Class<Serde<T>> cls, Map<String, ?> configs) {
    try {
        final Serde<T> serde = getConfiguredInstance(cls, configs);
        serde.configure(configs, true);
        return serde;
    } catch (final Exception e) {
        throw new KafkaException(
            String.format("Failed to configure key serde %s", cls), e);
    }
}
 
Example 5
Source File: AvroGenericUtils.java    From simplesource with Apache License 2.0 5 votes vote down vote up
public static Serde<GenericRecord> genericAvroSerde(
        final String schemaRegistryUrl,
        final boolean useMockSchemaRegistry,
        final boolean isKey,
        final SchemaNameStrategy schemaNameStrategy) {
    final Map<String, Object> configMap = avroSchemaRegistryConfig(schemaRegistryUrl, schemaNameStrategy);
    final Serde<GenericRecord> serde = useMockSchemaRegistry
            ? new GenericAvroSerde(new MockSchemaRegistryClient())
            : new GenericAvroSerde();
    serde.configure(configMap, isKey);
    return serde;
}
 
Example 6
Source File: KeyValueSerdeResolver.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
private Serde<?> getValueSerde(String valueSerdeString)
		throws ClassNotFoundException {
	Serde<?> valueSerde;
	if (StringUtils.hasText(valueSerdeString)) {
		valueSerde = Utils.newInstance(valueSerdeString, Serde.class);
	}
	else {
		valueSerde = getFallbackSerde("default.value.serde");
	}
	valueSerde.configure(this.streamConfigGlobalProperties, false);
	return valueSerde;
}
 
Example 7
Source File: PosSerdes.java    From Kafka-Streams-Real-time-Stream-Processing with The Unlicense 4 votes vote down vote up
static Serde<PosInvoice> PosInvoice() {
    final Serde<PosInvoice> specificAvroSerde = new SpecificAvroSerde<>();
    specificAvroSerde.configure(serdeConfig, false);
    return specificAvroSerde;
}
 
Example 8
Source File: PosSerdes.java    From Kafka-Streams-Real-time-Stream-Processing with The Unlicense 4 votes vote down vote up
static Serde<Notification> Notification() {
    final Serde<Notification> specificAvroSerde = new SpecificAvroSerde<>();
    specificAvroSerde.configure(serdeConfig, false);
    return specificAvroSerde;
}
 
Example 9
Source File: PosSerdes.java    From Kafka-Streams-Real-time-Stream-Processing with The Unlicense 4 votes vote down vote up
static Serde<HadoopRecord> HadoopRecord() {
    final Serde<HadoopRecord> specificAvroSerde = new SpecificAvroSerde<>();
    specificAvroSerde.configure(serdeConfig, false);
    return specificAvroSerde;
}