Java Code Examples for org.apache.kafka.streams.kstream.Produced#with()

The following examples show how to use org.apache.kafka.streams.kstream.Produced#with() . 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: TopologyContext.java    From simplesource with Apache License 2.0 5 votes vote down vote up
public TopologyContext(AggregateSpec<K, C, E, A> aggregateSpec) {
    this.aggregateSpec = aggregateSpec;
    this.commandResponseRetentionInSeconds = aggregateSpec.generation().stateStoreSpec().retentionInSeconds();
    serdes = aggregateSpec.serialization().serdes();

    commandRequestConsumed = Consumed.with(serdes().aggregateKey(), serdes().commandRequest());
    commandResponseConsumed = Consumed.with(serdes().aggregateKey(), serdes().commandResponse());
    eventsConsumedProduced = Produced.with(serdes().aggregateKey(), serdes().valueWithSequence());
    aggregatedUpdateProduced = Produced.with(serdes().aggregateKey(), serdes().aggregateUpdate());
    commandResponseProduced = Produced.with(serdes().aggregateKey(), serdes().commandResponse());
    serializedCommandResponse = Serialized.with(serdes().commandId(), serdes().commandResponse());
    aggregator = aggregateSpec.generation().aggregator();
    initialValue = aggregateSpec.generation().initialValue();
}
 
Example 2
Source File: KStreamBinder.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void to(boolean isNativeEncoding, String name,
				KStream<Object, Object> outboundBindTarget, Serde<Object> keySerde,
				Serde<Object> valueSerde, KafkaStreamsProducerProperties properties) {
	final Produced<Object, Object> produced = Produced.with(keySerde, valueSerde);
	StreamPartitioner streamPartitioner = null;
	if (!StringUtils.isEmpty(properties.getStreamPartitionerBeanName())) {
		streamPartitioner = getApplicationContext().getBean(properties.getStreamPartitionerBeanName(),
				StreamPartitioner.class);
	}
	if (streamPartitioner != null) {
		produced.withStreamPartitioner(streamPartitioner);
	}
	if (!isNativeEncoding) {
		LOG.info("Native encoding is disabled for " + name
				+ ". Outbound message conversion done by Spring Cloud Stream.");
		outboundBindTarget.filter((k, v) -> v == null)
				.to(name, produced);
		this.kafkaStreamsMessageConversionDelegate
				.serializeOnOutbound(outboundBindTarget)
				.to(name, produced);
	}
	else {
		LOG.info("Native encoding is enabled for " + name
				+ ". Outbound serialization done at the broker.");
		outboundBindTarget.to(name, produced);
	}
}
 
Example 3
Source File: PressureDatetimeExtractorTest.java    From kafka-tutorials with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
    this.pressureSerde = makePressureAlertSerde();

    Consumed<String, PressureAlert> consumedPressure = Consumed
            .with(Serdes.String(), pressureSerde)
            .withTimestampExtractor(timestampExtractor);

    Produced<String, PressureAlert> producedPressure = Produced.with(Serdes.String(), pressureSerde);

    StreamsBuilder builder = new StreamsBuilder();

    builder.stream(this.inputTopic, consumedPressure).to(this.outputTopic, producedPressure);

    this.topologyTestDriver = new TopologyTestDriver(builder.build(), WindowFinalResult.buildProperties(config));
}
 
Example 4
Source File: SerdesPair.java    From kafka-encryption with Apache License 2.0 2 votes vote down vote up
/**
 * Build a {@link Produced} using the keySerde and valueSerde of the pair
 *
 * @return
 */
public Produced<K, V> toProduced() {
    return Produced.with(keySerde, valueSerde);
}