Search in sources :

Example 1 with Serde

use of org.apache.kafka.common.serialization.Serde in project apache-kafka-on-k8s by banzaicloud.

the class SessionWindowedSerializer method configure.

@SuppressWarnings("unchecked")
@Override
public void configure(final Map<String, ?> configs, final boolean isKey) {
    if (inner == null) {
        String propertyName = isKey ? StreamsConfig.DEFAULT_WINDOWED_KEY_SERDE_INNER_CLASS : StreamsConfig.DEFAULT_WINDOWED_VALUE_SERDE_INNER_CLASS;
        String value = (String) configs.get(propertyName);
        try {
            inner = Serde.class.cast(Utils.newInstance(value, Serde.class)).serializer();
            inner.configure(configs, isKey);
        } catch (final ClassNotFoundException e) {
            throw new ConfigException(propertyName, value, "Serde class " + value + " could not be found.");
        }
    }
}
Also used : Serde(org.apache.kafka.common.serialization.Serde) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 2 with Serde

use of org.apache.kafka.common.serialization.Serde in project apache-kafka-on-k8s by banzaicloud.

the class TimeWindowedSerializer method configure.

@SuppressWarnings("unchecked")
@Override
public void configure(final Map<String, ?> configs, final boolean isKey) {
    if (inner == null) {
        final String propertyName = isKey ? StreamsConfig.DEFAULT_WINDOWED_KEY_SERDE_INNER_CLASS : StreamsConfig.DEFAULT_WINDOWED_VALUE_SERDE_INNER_CLASS;
        final String value = (String) configs.get(propertyName);
        try {
            inner = Serde.class.cast(Utils.newInstance(value, Serde.class)).serializer();
            inner.configure(configs, isKey);
        } catch (final ClassNotFoundException e) {
            throw new ConfigException(propertyName, value, "Serde class " + value + " could not be found.");
        }
    }
}
Also used : Serde(org.apache.kafka.common.serialization.Serde) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 3 with Serde

use of org.apache.kafka.common.serialization.Serde in project apache-kafka-on-k8s by banzaicloud.

the class StreamsConfig method defaultValueSerde.

/**
 * Return an {@link Serde#configure(Map, boolean) configured} instance of {@link #DEFAULT_VALUE_SERDE_CLASS_CONFIG value
 * Serde class}.
 *
 * @return an configured instance of value Serde class
 */
public Serde defaultValueSerde() {
    Object valueSerdeConfigSetting = get(VALUE_SERDE_CLASS_CONFIG);
    try {
        Serde<?> serde = getConfiguredInstance(VALUE_SERDE_CLASS_CONFIG, Serde.class);
        if (serde == null) {
            valueSerdeConfigSetting = get(DEFAULT_VALUE_SERDE_CLASS_CONFIG);
            serde = getConfiguredInstance(DEFAULT_VALUE_SERDE_CLASS_CONFIG, Serde.class);
        }
        serde.configure(originals(), false);
        return serde;
    } catch (final Exception e) {
        throw new StreamsException(String.format("Failed to configure value serde %s", valueSerdeConfigSetting), e);
    }
}
Also used : Serde(org.apache.kafka.common.serialization.Serde) StreamsException(org.apache.kafka.streams.errors.StreamsException) StreamsException(org.apache.kafka.streams.errors.StreamsException)

Example 4 with Serde

use of org.apache.kafka.common.serialization.Serde in project apache-kafka-on-k8s by banzaicloud.

the class StreamsConfig method defaultKeySerde.

/**
 * Return an {@link Serde#configure(Map, boolean) configured} instance of {@link #DEFAULT_KEY_SERDE_CLASS_CONFIG key Serde
 * class}.
 *
 * @return an configured instance of key Serde class
 */
public Serde defaultKeySerde() {
    Object keySerdeConfigSetting = get(KEY_SERDE_CLASS_CONFIG);
    try {
        Serde<?> serde = getConfiguredInstance(KEY_SERDE_CLASS_CONFIG, Serde.class);
        if (serde == null) {
            keySerdeConfigSetting = get(DEFAULT_KEY_SERDE_CLASS_CONFIG);
            serde = getConfiguredInstance(DEFAULT_KEY_SERDE_CLASS_CONFIG, Serde.class);
        }
        serde.configure(originals(), true);
        return serde;
    } catch (final Exception e) {
        throw new StreamsException(String.format("Failed to configure key serde %s", keySerdeConfigSetting), e);
    }
}
Also used : Serde(org.apache.kafka.common.serialization.Serde) StreamsException(org.apache.kafka.streams.errors.StreamsException) StreamsException(org.apache.kafka.streams.errors.StreamsException)

Example 5 with Serde

use of org.apache.kafka.common.serialization.Serde in project apache-kafka-on-k8s by banzaicloud.

the class SessionWindowedDeserializer method configure.

@SuppressWarnings("unchecked")
@Override
public void configure(final Map<String, ?> configs, final boolean isKey) {
    if (inner == null) {
        final String propertyName = isKey ? StreamsConfig.DEFAULT_WINDOWED_KEY_SERDE_INNER_CLASS : StreamsConfig.DEFAULT_WINDOWED_VALUE_SERDE_INNER_CLASS;
        final String value = (String) configs.get(propertyName);
        try {
            inner = Serde.class.cast(Utils.newInstance(value, Serde.class)).deserializer();
            inner.configure(configs, isKey);
        } catch (final ClassNotFoundException e) {
            throw new ConfigException(propertyName, value, "Serde class " + value + " could not be found.");
        }
    }
}
Also used : Serde(org.apache.kafka.common.serialization.Serde) ConfigException(org.apache.kafka.common.config.ConfigException)

Aggregations

Serde (org.apache.kafka.common.serialization.Serde)20 Serdes (org.apache.kafka.common.serialization.Serdes)12 Properties (java.util.Properties)11 KafkaStreams (org.apache.kafka.streams.KafkaStreams)11 StreamsConfig (org.apache.kafka.streams.StreamsConfig)11 KStream (org.apache.kafka.streams.kstream.KStream)11 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)10 Produced (org.apache.kafka.streams.kstream.Produced)10 KTable (org.apache.kafka.streams.kstream.KTable)9 Arrays (java.util.Arrays)8 KeyValue (org.apache.kafka.streams.KeyValue)8 ConsumerConfig (org.apache.kafka.clients.consumer.ConsumerConfig)7 List (java.util.List)5 Test (org.junit.Test)5 EmbeddedSingleNodeKafkaCluster (io.confluent.examples.streams.kafka.EmbeddedSingleNodeKafkaCluster)4 TestUtils (org.apache.kafka.test.TestUtils)4 AbstractKafkaAvroSerDeConfig (io.confluent.kafka.serializers.AbstractKafkaAvroSerDeConfig)3 Collections (java.util.Collections)3 TimeUnit (java.util.concurrent.TimeUnit)3 ProducerConfig (org.apache.kafka.clients.producer.ProducerConfig)3