Search in sources :

Example 1 with StoreBuilder

use of org.apache.kafka.streams.state.StoreBuilder in project apache-kafka-on-k8s by banzaicloud.

the class TopologyTest method addProcessorWithStore.

private TopologyDescription.Processor addProcessorWithStore(final String processorName, final String[] storeNames, final boolean newStores, final TopologyDescription.Node... parents) {
    final String[] parentNames = new String[parents.length];
    for (int i = 0; i < parents.length; ++i) {
        parentNames[i] = parents[i].name();
    }
    topology.addProcessor(processorName, new MockProcessorSupplier(), parentNames);
    if (newStores) {
        for (final String store : storeNames) {
            final StoreBuilder storeBuilder = EasyMock.createNiceMock(StoreBuilder.class);
            EasyMock.expect(storeBuilder.name()).andReturn(store).anyTimes();
            EasyMock.replay(storeBuilder);
            topology.addStateStore(storeBuilder, processorName);
        }
    } else {
        topology.connectProcessorAndStateStores(processorName, storeNames);
    }
    final TopologyDescription.Processor expectedProcessorNode = new InternalTopologyBuilder.Processor(processorName, new HashSet<>(Arrays.asList(storeNames)));
    for (final TopologyDescription.Node parent : parents) {
        ((InternalTopologyBuilder.AbstractNode) parent).addSuccessor(expectedProcessorNode);
        ((InternalTopologyBuilder.AbstractNode) expectedProcessorNode).addPredecessor(parent);
    }
    return expectedProcessorNode;
}
Also used : Processor(org.apache.kafka.streams.processor.Processor) MockProcessorSupplier(org.apache.kafka.test.MockProcessorSupplier) KeyValueStoreBuilder(org.apache.kafka.streams.state.internals.KeyValueStoreBuilder) StoreBuilder(org.apache.kafka.streams.state.StoreBuilder)

Example 2 with StoreBuilder

use of org.apache.kafka.streams.state.StoreBuilder in project apache-kafka-on-k8s by banzaicloud.

the class InternalStreamsBuilder method globalTable.

@SuppressWarnings("unchecked")
public <K, V> GlobalKTable<K, V> globalTable(final String topic, final ConsumedInternal<K, V> consumed, final MaterializedInternal<K, V, KeyValueStore<Bytes, byte[]>> materialized) {
    Objects.requireNonNull(consumed, "consumed can't be null");
    Objects.requireNonNull(materialized, "materialized can't be null");
    // explicitly disable logging for global stores
    materialized.withLoggingDisabled();
    final StoreBuilder storeBuilder = new KeyValueStoreMaterializer<>(materialized).materialize();
    final String sourceName = newProcessorName(KStreamImpl.SOURCE_NAME);
    final String processorName = newProcessorName(KTableImpl.SOURCE_NAME);
    final KTableSource<K, V> tableSource = new KTableSource<>(storeBuilder.name());
    internalTopologyBuilder.addGlobalStore(storeBuilder, sourceName, consumed.timestampExtractor(), consumed.keyDeserializer(), consumed.valueDeserializer(), topic, processorName, tableSource);
    return new GlobalKTableImpl<>(new KTableSourceValueGetterSupplier<K, V>(storeBuilder.name()), materialized.isQueryable());
}
Also used : StoreBuilder(org.apache.kafka.streams.state.StoreBuilder)

Example 3 with StoreBuilder

use of org.apache.kafka.streams.state.StoreBuilder in project apache-kafka-on-k8s by banzaicloud.

the class KTableImpl method doFilter.

private KTable<K, V> doFilter(final Predicate<? super K, ? super V> predicate, final MaterializedInternal<K, V, KeyValueStore<Bytes, byte[]>> materialized, final boolean filterNot) {
    String name = builder.newProcessorName(FILTER_NAME);
    KTableProcessorSupplier<K, V, V> processorSupplier = new KTableFilter<>(this, predicate, filterNot, materialized.storeName());
    builder.internalTopologyBuilder.addProcessor(name, processorSupplier, this.name);
    final StoreBuilder builder = new KeyValueStoreMaterializer<>(materialized).materialize();
    this.builder.internalTopologyBuilder.addStateStore(builder, name);
    return new KTableImpl<>(this.builder, name, processorSupplier, this.keySerde, this.valSerde, sourceNodes, builder.name(), true);
}
Also used : StoreBuilder(org.apache.kafka.streams.state.StoreBuilder)

Example 4 with StoreBuilder

use of org.apache.kafka.streams.state.StoreBuilder in project apache-kafka-on-k8s by banzaicloud.

the class RocksDBKeyValueStoreTest method createKeyValueStore.

@SuppressWarnings("unchecked")
@Override
protected <K, V> KeyValueStore<K, V> createKeyValueStore(final ProcessorContext context) {
    final StoreBuilder storeBuilder = Stores.keyValueStoreBuilder(Stores.persistentKeyValueStore("my-store"), (Serde<K>) context.keySerde(), (Serde<V>) context.valueSerde());
    final StateStore store = storeBuilder.build();
    store.init(context, store);
    return (KeyValueStore<K, V>) store;
}
Also used : StoreBuilder(org.apache.kafka.streams.state.StoreBuilder) StateStore(org.apache.kafka.streams.processor.StateStore) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore)

Example 5 with StoreBuilder

use of org.apache.kafka.streams.state.StoreBuilder in project apache-kafka-on-k8s by banzaicloud.

the class InMemoryKeyValueStoreTest method createKeyValueStore.

@SuppressWarnings("unchecked")
@Override
protected <K, V> KeyValueStore<K, V> createKeyValueStore(final ProcessorContext context) {
    final StoreBuilder storeBuilder = Stores.keyValueStoreBuilder(Stores.inMemoryKeyValueStore("my-store"), (Serde<K>) context.keySerde(), (Serde<V>) context.valueSerde());
    final StateStore store = storeBuilder.build();
    store.init(context, store);
    return (KeyValueStore<K, V>) store;
}
Also used : StoreBuilder(org.apache.kafka.streams.state.StoreBuilder) StateStore(org.apache.kafka.streams.processor.StateStore) KeyValueStore(org.apache.kafka.streams.state.KeyValueStore)

Aggregations

StoreBuilder (org.apache.kafka.streams.state.StoreBuilder)13 KeyValueStore (org.apache.kafka.streams.state.KeyValueStore)6 StateStore (org.apache.kafka.streams.processor.StateStore)4 Serde (org.apache.kafka.common.serialization.Serde)2 Serdes (org.apache.kafka.common.serialization.Serdes)2 KafkaStreams (org.apache.kafka.streams.KafkaStreams)2 KeyValue (org.apache.kafka.streams.KeyValue)2 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)2 KStream (org.apache.kafka.streams.kstream.KStream)2 Transformer (org.apache.kafka.streams.kstream.Transformer)2 ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)2 Stores (org.apache.kafka.streams.state.Stores)2 Order (io.confluent.examples.streams.avro.microservices.Order)1 OrderState (io.confluent.examples.streams.avro.microservices.OrderState)1 OrderValidation (io.confluent.examples.streams.avro.microservices.OrderValidation)1 FAIL (io.confluent.examples.streams.avro.microservices.OrderValidationResult.FAIL)1 PASS (io.confluent.examples.streams.avro.microservices.OrderValidationResult.PASS)1 INVENTORY_CHECK (io.confluent.examples.streams.avro.microservices.OrderValidationType.INVENTORY_CHECK)1 Product (io.confluent.examples.streams.avro.microservices.Product)1 EmbeddedSingleNodeKafkaCluster (io.confluent.examples.streams.kafka.EmbeddedSingleNodeKafkaCluster)1