Search in sources :

Example 6 with ProcessorContext

use of org.apache.kafka.streams.processor.ProcessorContext in project kafka by apache.

the class SimpleBenchmark method createKafkaStreamsWithSink.

private KafkaStreams createKafkaStreamsWithSink(String topic, final CountDownLatch latch) {
    final Properties props = setStreamProperties("simple-benchmark-streams-with-sink");
    KStreamBuilder builder = new KStreamBuilder();
    KStream<Integer, byte[]> source = builder.stream(INTEGER_SERDE, BYTE_SERDE, topic);
    source.to(INTEGER_SERDE, BYTE_SERDE, SINK_TOPIC);
    source.process(new ProcessorSupplier<Integer, byte[]>() {

        @Override
        public Processor<Integer, byte[]> get() {
            return new AbstractProcessor<Integer, byte[]>() {

                @Override
                public void init(ProcessorContext context) {
                }

                @Override
                public void process(Integer key, byte[] value) {
                    processedRecords++;
                    processedBytes += value.length + Integer.SIZE;
                    if (processedRecords == numRecords) {
                        latch.countDown();
                    }
                }

                @Override
                public void punctuate(long timestamp) {
                }

                @Override
                public void close() {
                }
            };
        }
    });
    return createKafkaStreamsWithExceptionHandler(builder, props);
}
Also used : KStreamBuilder(org.apache.kafka.streams.kstream.KStreamBuilder) Processor(org.apache.kafka.streams.processor.Processor) AbstractProcessor(org.apache.kafka.streams.processor.AbstractProcessor) Properties(java.util.Properties) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext)

Example 7 with ProcessorContext

use of org.apache.kafka.streams.processor.ProcessorContext in project kafka by apache.

the class SimpleBenchmark method createKafkaStreams.

private KafkaStreams createKafkaStreams(String topic, final CountDownLatch latch) {
    Properties props = setStreamProperties("simple-benchmark-streams");
    KStreamBuilder builder = new KStreamBuilder();
    KStream<Integer, byte[]> source = builder.stream(INTEGER_SERDE, BYTE_SERDE, topic);
    source.process(new ProcessorSupplier<Integer, byte[]>() {

        @Override
        public Processor<Integer, byte[]> get() {
            return new AbstractProcessor<Integer, byte[]>() {

                @Override
                public void init(ProcessorContext context) {
                }

                @Override
                public void process(Integer key, byte[] value) {
                    processedRecords++;
                    processedBytes += value.length + Integer.SIZE;
                    if (processedRecords == numRecords) {
                        latch.countDown();
                    }
                }

                @Override
                public void punctuate(long timestamp) {
                }

                @Override
                public void close() {
                }
            };
        }
    });
    return createKafkaStreamsWithExceptionHandler(builder, props);
}
Also used : KStreamBuilder(org.apache.kafka.streams.kstream.KStreamBuilder) Processor(org.apache.kafka.streams.processor.Processor) AbstractProcessor(org.apache.kafka.streams.processor.AbstractProcessor) Properties(java.util.Properties) ProcessorContext(org.apache.kafka.streams.processor.ProcessorContext)

Aggregations

ProcessorContext (org.apache.kafka.streams.processor.ProcessorContext)7 KStreamBuilder (org.apache.kafka.streams.kstream.KStreamBuilder)5 AbstractProcessor (org.apache.kafka.streams.processor.AbstractProcessor)4 Test (org.junit.Test)4 Properties (java.util.Properties)3 Processor (org.apache.kafka.streams.processor.Processor)3 KStreamTestDriver (org.apache.kafka.test.KStreamTestDriver)2 MockProcessorSupplier (org.apache.kafka.test.MockProcessorSupplier)2 NoOpProcessorContext (org.apache.kafka.test.NoOpProcessorContext)2 File (java.io.File)1 KafkaException (org.apache.kafka.common.KafkaException)1 PartitionInfo (org.apache.kafka.common.PartitionInfo)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 Metrics (org.apache.kafka.common.metrics.Metrics)1 MockTime (org.apache.kafka.common.utils.MockTime)1 KeyValue (org.apache.kafka.streams.KeyValue)1 StreamsConfig (org.apache.kafka.streams.StreamsConfig)1 StreamsMetrics (org.apache.kafka.streams.StreamsMetrics)1 StreamsException (org.apache.kafka.streams.errors.StreamsException)1 Transformer (org.apache.kafka.streams.kstream.Transformer)1