org.apache.kafka.streams.kstream.ValueMapperWithKey Java Examples

The following examples show how to use org.apache.kafka.streams.kstream.ValueMapperWithKey. 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: KGraph.java    From kafka-graphs with Apache License 2.0 4 votes vote down vote up
public <NV> KGraph<K, NV, EV> mapVertices(ValueMapperWithKey<K, VV, NV> mapper, Serde<NV> newVertexValueSerde) {
    KTable<K, NV> mappedVertices = vertices.mapValues(mapper, Materialized.<K, NV, KeyValueStore<Bytes, byte[]>>as(
        generateStoreName()).withKeySerde(keySerde()).withValueSerde(newVertexValueSerde));
    return new KGraph<>(mappedVertices, edges,
        GraphSerialized.with(keySerde(), newVertexValueSerde, edgeValueSerde()));
}
 
Example #2
Source File: KGraph.java    From kafka-graphs with Apache License 2.0 4 votes vote down vote up
public <NV> KGraph<K, VV, NV> mapEdges(ValueMapperWithKey<Edge<K>, EV, NV> mapper, Serde<NV> newEdgeValueSerde) {
    KTable<Edge<K>, NV> mappedEdges = edges.mapValues(mapper, Materialized.<Edge<K>, NV, KeyValueStore<Bytes, byte[]>>as(
        generateStoreName()).withKeySerde(new KryoSerde<>()).withValueSerde(newEdgeValueSerde));
    return new KGraph<>(vertices, mappedEdges,
        GraphSerialized.with(keySerde(), vertexValueSerde(), newEdgeValueSerde));
}
 
Example #3
Source File: KafkaStreamsTracing.java    From brave with Apache License 2.0 3 votes vote down vote up
/**
 * Create a mapValues transformer, similar to {@link KStream#mapValues(ValueMapperWithKey)}, where
 * its mapper action will be recorded in a new span with the indicated name.
 *
 * <p>Simple example using Kafka Streams DSL:
 * <pre>{@code
 * StreamsBuilder builder = new StreamsBuilder();
 * builder.stream(inputTopic)
 *        .transformValues(kafkaStreamsTracing.mapValues("myMapValues", (k, v) -> ...)
 *        .to(outputTopic);
 * }</pre>
 */
public <K, V, VR> ValueTransformerWithKeySupplier<K, V, VR> mapValues(String spanName,
  ValueMapperWithKey<K, V, VR> mapper) {
  return new TracingValueTransformerWithKeySupplier<>(this, spanName, () ->
    new AbstractTracingValueTransformerWithKey<K, V, VR>() {
      @Override public VR transform(K readOnlyKey, V value) {
        return mapper.apply(readOnlyKey, value);
      }
    });
}