use of io.confluent.examples.streams.microservices.domain.Schemas.Topics.PAYMENTS in project kafka-streams-examples by confluentinc.
the class EmailService method processStreams.
private KafkaStreams processStreams(final String bootstrapServers, final String stateDir) {
KStreamBuilder builder = new KStreamBuilder();
// Create the streams/tables for the join
KStream<String, Order> orders = builder.stream(ORDERS.keySerde(), ORDERS.valueSerde(), ORDERS.name());
KStream<String, Payment> payments = builder.stream(PAYMENTS.keySerde(), PAYMENTS.valueSerde(), PAYMENTS.name());
GlobalKTable<Long, Customer> customers = builder.globalTable(CUSTOMERS.keySerde(), CUSTOMERS.valueSerde(), CUSTOMERS.name());
// Rekey payments to be by OrderId for the windowed join
payments = payments.selectKey((s, payment) -> payment.getOrderId());
// Join the two streams and the table then send an email for each
orders.join(payments, EmailTuple::new, // Join Orders and Payments streams
JoinWindows.of(1 * MIN), serdes).join(customers, (key1, tuple) -> tuple.order.getCustomerId(), // note how, because we use a GKtable, we can join on any attribute of the Customer.
(tuple, customer) -> tuple.setCustomer(customer)).peek((key, emailTuple) -> emailer.sendEmail(emailTuple));
return new KafkaStreams(builder, baseStreamsConfig(bootstrapServers, stateDir, APP_ID));
}
Aggregations