Search in sources :

Example 1 with CUSTOMERS

use of io.confluent.examples.streams.microservices.domain.Schemas.Topics.CUSTOMERS 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));
}
Also used : KStreamBuilder(org.apache.kafka.streams.kstream.KStreamBuilder) Order(io.confluent.examples.streams.avro.microservices.Order) Payment(io.confluent.examples.streams.avro.microservices.Payment) MIN(io.confluent.examples.streams.microservices.util.MicroserviceUtils.MIN) Logger(org.slf4j.Logger) KStreamBuilder(org.apache.kafka.streams.kstream.KStreamBuilder) LoggerFactory(org.slf4j.LoggerFactory) CUSTOMERS(io.confluent.examples.streams.microservices.domain.Schemas.Topics.CUSTOMERS) ORDERS(io.confluent.examples.streams.microservices.domain.Schemas.Topics.ORDERS) KStream(org.apache.kafka.streams.kstream.KStream) Joined(org.apache.kafka.streams.kstream.Joined) Customer(io.confluent.examples.streams.avro.microservices.Customer) MicroserviceUtils.addShutdownHookAndBlock(io.confluent.examples.streams.microservices.util.MicroserviceUtils.addShutdownHookAndBlock) JoinWindows(org.apache.kafka.streams.kstream.JoinWindows) GlobalKTable(org.apache.kafka.streams.kstream.GlobalKTable) MicroserviceUtils.baseStreamsConfig(io.confluent.examples.streams.microservices.util.MicroserviceUtils.baseStreamsConfig) PAYMENTS(io.confluent.examples.streams.microservices.domain.Schemas.Topics.PAYMENTS) KafkaStreams(org.apache.kafka.streams.KafkaStreams) Order(io.confluent.examples.streams.avro.microservices.Order) MicroserviceUtils.parseArgsAndConfigure(io.confluent.examples.streams.microservices.util.MicroserviceUtils.parseArgsAndConfigure) Payment(io.confluent.examples.streams.avro.microservices.Payment) KafkaStreams(org.apache.kafka.streams.KafkaStreams) Customer(io.confluent.examples.streams.avro.microservices.Customer)

Aggregations

Customer (io.confluent.examples.streams.avro.microservices.Customer)1 Order (io.confluent.examples.streams.avro.microservices.Order)1 Payment (io.confluent.examples.streams.avro.microservices.Payment)1 CUSTOMERS (io.confluent.examples.streams.microservices.domain.Schemas.Topics.CUSTOMERS)1 ORDERS (io.confluent.examples.streams.microservices.domain.Schemas.Topics.ORDERS)1 PAYMENTS (io.confluent.examples.streams.microservices.domain.Schemas.Topics.PAYMENTS)1 MIN (io.confluent.examples.streams.microservices.util.MicroserviceUtils.MIN)1 MicroserviceUtils.addShutdownHookAndBlock (io.confluent.examples.streams.microservices.util.MicroserviceUtils.addShutdownHookAndBlock)1 MicroserviceUtils.baseStreamsConfig (io.confluent.examples.streams.microservices.util.MicroserviceUtils.baseStreamsConfig)1 MicroserviceUtils.parseArgsAndConfigure (io.confluent.examples.streams.microservices.util.MicroserviceUtils.parseArgsAndConfigure)1 KafkaStreams (org.apache.kafka.streams.KafkaStreams)1 GlobalKTable (org.apache.kafka.streams.kstream.GlobalKTable)1 JoinWindows (org.apache.kafka.streams.kstream.JoinWindows)1 Joined (org.apache.kafka.streams.kstream.Joined)1 KStream (org.apache.kafka.streams.kstream.KStream)1 KStreamBuilder (org.apache.kafka.streams.kstream.KStreamBuilder)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1