org.apache.kafka.streams.processor.Processor Java Examples

The following examples show how to use org.apache.kafka.streams.processor.Processor. 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: KafkaStreamsStateStoreIntegrationTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
@StreamListener("input")
@KafkaStreamsStateStore(name = "mystate", type = KafkaStreamsStateStoreProperties.StoreType.WINDOW, lengthMs = 300000, retentionMs = 300000)
@SuppressWarnings({ "deprecation", "unchecked" })
public void process(KStream<Object, Product> input) {

	input.process(() -> new Processor<Object, Product>() {

		@Override
		public void init(ProcessorContext processorContext) {
			state = (WindowStore) processorContext.getStateStore("mystate");
		}

		@Override
		public void process(Object s, Product product) {
			processed = true;
		}

		@Override
		public void close() {
			if (state != null) {
				state.close();
			}
		}
	}, "mystate");
}
 
Example #2
Source File: KafkaStreamsStateStoreIntegrationTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
@StreamListener("input3")
@SuppressWarnings({"unchecked" })
public void process(KStream<Object, Product> input) {

	input.process(() -> new Processor<Object, Product>() {

		@Override
		public void init(ProcessorContext processorContext) {
			state = (WindowStore) processorContext.getStateStore("mystate");
		}

		@Override
		public void process(Object s, Product product) {
			processed = true;
		}

		@Override
		public void close() {
			if (state != null) {
				state.close();
			}
		}
	}, "mystate");
}
 
Example #3
Source File: KafkaStreamsFunctionStateStoreTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
@Bean
public java.util.function.BiConsumer<KStream<Object, String>, KStream<Object, String>> process() {
	return (input0, input1) ->
			input0.process((ProcessorSupplier<Object, String>) () -> new Processor<Object, String>() {
				@Override
				@SuppressWarnings("unchecked")
				public void init(ProcessorContext context) {
					state1 = (KeyValueStore<Long, Long>) context.getStateStore("my-store");
					state2 = (WindowStore<Long, Long>) context.getStateStore("other-store");
				}

				@Override
				public void process(Object key, String value) {
					processed1 = true;
				}

				@Override
				public void close() {

				}
			}, "my-store", "other-store");
}
 
Example #4
Source File: KafkaStreamsFunctionStateStoreTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
@Bean
public java.util.function.Consumer<KTable<Object, String>> hello() {
	return input -> {
		input.toStream().process(() -> new Processor<Object, String>() {
			@Override
			@SuppressWarnings("unchecked")
			public void init(ProcessorContext context) {
				state3 = (KeyValueStore<Long, Long>) context.getStateStore("my-store");
				state4 = (WindowStore<Long, Long>) context.getStateStore("other-store");
			}

			@Override
			public void process(Object key, String value) {
				processed2 = true;
			}

			@Override
			public void close() {

			}
		}, "my-store", "other-store");
	};
}
 
Example #5
Source File: KafkaStreamsTracingTest.java    From brave with Apache License 2.0 5 votes vote down vote up
@Test
public void processorSupplier_should_tag_app_id_and_task_id() {
  Processor<String, String> processor = fakeProcessorSupplier.get();
  processor.init(processorContextSupplier.apply(new RecordHeaders()));
  processor.process(TEST_KEY, TEST_VALUE);

  assertThat(spans.get(0).tags())
    .containsOnly(
      entry("kafka.streams.application.id", TEST_APPLICATION_ID),
      entry("kafka.streams.task.id", TEST_TASK_ID));
}
 
Example #6
Source File: CPUMetricStreamHandler.java    From kafka-streams-example with Apache License 2.0 5 votes vote down vote up
private TopologyBuilder processingTopologyBuilder() {

        StateStoreSupplier machineToAvgCPUUsageStore
                = Stores.create(AVG_STORE_NAME)
                        .withStringKeys()
                        .withDoubleValues()
                        .inMemory()
                        .build();

        StateStoreSupplier machineToNumOfRecordsReadStore
                = Stores.create(NUM_RECORDS_STORE_NAME)
                        .withStringKeys()
                        .withIntegerValues()
                        .inMemory()
                        .build();

        TopologyBuilder builder = new TopologyBuilder();

        builder.addSource(SOURCE_NAME, TOPIC_NAME)
                .addProcessor(PROCESSOR_NAME, new ProcessorSupplier() {
                    @Override
                    public Processor get() {
                        return new CPUCumulativeAverageProcessor();
                    }
                }, SOURCE_NAME)
                .addStateStore(machineToAvgCPUUsageStore, PROCESSOR_NAME)
                .addStateStore(machineToNumOfRecordsReadStore, PROCESSOR_NAME);

        LOGGER.info("Kafka streams processing topology ready");

        return builder;
    }
 
Example #7
Source File: KafkaStreamsStateStoreIntegrationTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@StreamListener
@KafkaStreamsStateStore(name = "mystate", type = KafkaStreamsStateStoreProperties.StoreType.WINDOW, lengthMs = 300000, retentionMs = 300000)
@SuppressWarnings({ "deprecation", "unchecked" })
public void process(@Input("input1")KStream<Object, Product> input, @Input("input2")KStream<Object, Product> input2) {

	input.process(() -> new Processor<Object, Product>() {

		@Override
		public void init(ProcessorContext processorContext) {
			state = (WindowStore) processorContext.getStateStore("mystate");
		}

		@Override
		public void process(Object s, Product product) {
			processed = true;
		}

		@Override
		public void close() {
			if (state != null) {
				state.close();
			}
		}
	}, "mystate");

	//simple use of input2, we are not using input2 for anything other than triggering some test behavior.
	input2.foreach((key, value) -> { });
}
 
Example #8
Source File: TracingProcessor.java    From brave with Apache License 2.0 5 votes vote down vote up
TracingProcessor(KafkaStreamsTracing kafkaStreamsTracing,
  String spanName, Processor<K, V> delegateProcessor) {
  this.kafkaStreamsTracing = kafkaStreamsTracing;
  this.tracer = kafkaStreamsTracing.tracer;
  this.spanName = spanName;
  this.delegateProcessor = delegateProcessor;
}
 
Example #9
Source File: StatementPatternProcessorSupplier.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public Processor<String, VisibilityStatement> get() {
    return new StatementPatternProcessor(sp, resultFactory);
}
 
Example #10
Source File: TracingProcessorSupplier.java    From brave with Apache License 2.0 4 votes vote down vote up
/** This wraps process method to enable tracing. */
@Override public Processor<K, V> get() {
  return new TracingProcessor<>(kafkaStreamsTracing, spanName, delegateProcessorSupplier.get());
}
 
Example #11
Source File: FilterProcessorSupplier.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public Processor<Object, ProcessorResult> get() {
    return new FilterProcessor(filter, super.getResultFactory());
}
 
Example #12
Source File: JoinProcessorSupplier.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public Processor<Object, ProcessorResult> get() {
    return new JoinProcessor(stateStoreName, join, joinVars, allVars, super.getResultFactory());
}
 
Example #13
Source File: StatementOutputFormatterSupplier.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public Processor<Object, ProcessorResult> get() {
    return new StatementOutputFormatter();
}
 
Example #14
Source File: BindingSetOutputFormatterSupplier.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public Processor<Object, ProcessorResult> get() {
    return new BindingSetOutputFormatter();
}
 
Example #15
Source File: AggregationProcessorSupplier.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public Processor<Object, ProcessorResult> get() {
    return new AggregationProcessor(stateStoreName, aggNode, super.getResultFactory());
}
 
Example #16
Source File: ProjectionProcessorSupplier.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public Processor<Object, ProcessorResult> get() {
    return new ProjectionProcessor(projection, super.getResultFactory());
}
 
Example #17
Source File: MultiProjectionProcessorSupplier.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public Processor<Object, ProcessorResult> get() {
    return new MultiProjectionProcessor(multiProjection, super.getResultFactory());
}
 
Example #18
Source File: KStreamPrinter.java    From kafka-streams-in-action with Apache License 2.0 4 votes vote down vote up
@Override
public Processor get() {
    return new PrintingProcessor(this.name);
}
 
Example #19
Source File: CustomerStore.java    From cqrs-manager-for-distributed-reactive-services with Apache License 2.0 4 votes vote down vote up
@Override
public Processor<UUID, Map> get() {
    return this;
}
 
Example #20
Source File: MonitorProcessorSupplier.java    From DBus with Apache License 2.0 4 votes vote down vote up
@Override
public Processor get() {
    return new MonitorProcessor();
}
 
Example #21
Source File: GenericKStreamMap.java    From DBus with Apache License 2.0 4 votes vote down vote up
@Override
public Processor get() {
    return new GenericKStreamMapProcessor();
}