use of io.quarkus.kafka.client.serialization.ObjectMapperSerde in project AD482-apps by RedHatTraining.
the class AmountWasDepositedPipeline method onStart.
void onStart(@Observes StartupEvent startupEvent) {
StreamsBuilder builder = new StreamsBuilder();
ObjectMapperSerde<AmountWasDeposited> depositEventSerde = new ObjectMapperSerde<>(AmountWasDeposited.class);
ObjectMapperSerde<HighValueDepositWasDetected> highValueEventSerde = new ObjectMapperSerde<>(HighValueDepositWasDetected.class);
// TODO: Build the stream topology
builder.stream(AMOUNT_WAS_DEPOSITED_TOPIC, Consumed.with(Serdes.Long(), depositEventSerde)).filter((key, deposit) -> deposit.amount > 1000).map((key, deposit) -> {
logHighValueDepositAlert(deposit.bankAccountId, deposit.amount);
return new KeyValue<>(deposit.bankAccountId, new HighValueDepositWasDetected(deposit.bankAccountId, deposit.amount));
}).to(HIGH_VALUE_DEPOSIT_TOPIC, Produced.with(Serdes.Long(), highValueEventSerde));
// TODO: Create a Kafka streams and start it
streams = new KafkaStreams(builder.build(), generateStreamConfig());
streams.start();
}
use of io.quarkus.kafka.client.serialization.ObjectMapperSerde in project AD482-apps by RedHatTraining.
the class BankAccountWasCreatedPipeline method onStart.
void onStart(@Observes StartupEvent startupEvent) {
StreamsBuilder builder = new StreamsBuilder();
ObjectMapperSerde<BankAccountWasCreated> eventSerde = new ObjectMapperSerde<>(BankAccountWasCreated.class);
// TODO: Update the account type on each event
builder.stream(BANK_ACCOUNT_WAS_CREATED_TOPIC, Consumed.with(Serdes.Long(), eventSerde)).foreach((key, creation) -> {
updateAccountTypeFromEvent(creation);
});
// TODO: Create a Kafka streams and start it
streams = new KafkaStreams(builder.build(), generateStreamConfig());
streams.start();
}
use of io.quarkus.kafka.client.serialization.ObjectMapperSerde in project AD482-apps by RedHatTraining.
the class TumblingWindows method onStart.
void onStart(@Observes StartupEvent startupEvent) {
StreamsBuilder builder = new StreamsBuilder();
ObjectMapperSerde<PotentialCustomersWereDetected> customersEventSerde = new ObjectMapperSerde<>(PotentialCustomersWereDetected.class);
// TODO: Build the stream topology
builder.stream(POTENTIAL_CUSTOMERS_TOPIC, Consumed.with(Serdes.String(), customersEventSerde)).groupByKey().windowedBy(TimeWindows.of(Duration.ofSeconds(WINDOW_SIZE)).grace(Duration.ofSeconds(12))).count().toStream().print(Printed.toSysOut());
streams = new KafkaStreams(builder.build(), generateStreamConfig());
streams.start();
}
use of io.quarkus.kafka.client.serialization.ObjectMapperSerde in project AD482-apps by RedHatTraining.
the class StreamTopologyBuilder method buildTopology.
@Produces
public Topology buildTopology() {
StreamsBuilder builder = new StreamsBuilder();
ObjectMapperSerde<WindTurbine> turbineSerde = new ObjectMapperSerde<>(WindTurbine.class);
builder.table("turbines", Consumed.with(Serdes.Integer(), turbineSerde), Materialized.<Integer, WindTurbine, KeyValueStore<Bytes, byte[]>>as("turbines-store").withKeySerde(Serdes.Integer()).withValueSerde(turbineSerde));
KStream<Integer, Integer> wattsValuesStream = builder.stream("turbine-generated-watts", Consumed.with(Serdes.Integer(), Serdes.Integer()));
ObjectMapperSerde<MWattsMeasurement> mwattsMeasurementSerde = new ObjectMapperSerde<>(MWattsMeasurement.class);
wattsValuesStream.map((turbineId, watts) -> {
Double megawatts = (double) watts / 1000000;
MWattsMeasurement measurement = new MWattsMeasurement(turbineId, megawatts);
System.out.println("MAP - Turbine: " + turbineId + " | " + watts + " Watts -> " + megawatts + " MWatts");
return KeyValue.pair(turbineId, measurement);
}).to("turbine-generated-mwatts", Produced.with(Serdes.Integer(), mwattsMeasurementSerde));
ObjectMapperSerde<WindTurbineStats> statsSerde = new ObjectMapperSerde<>(WindTurbineStats.class);
wattsValuesStream.groupByKey().windowedBy(TimeWindows.of(Duration.ofSeconds(10)).advanceBy(Duration.ofSeconds(10)).grace(Duration.ofSeconds(12))).count().suppress(Suppressed.untilWindowCloses(unbounded())).toStream().map((windowedTurbineId, count) -> {
Integer turbineId = windowedTurbineId.key();
WindTurbineStats stats = new WindTurbineStats(turbineId, count);
System.out.println("COUNT - Turbine: " + turbineId + " | Count:" + count);
return KeyValue.pair(turbineId, stats);
}).to("turbine-stats", Produced.with(Serdes.Integer(), statsSerde));
return builder.build();
}
use of io.quarkus.kafka.client.serialization.ObjectMapperSerde in project AD482-apps by RedHatTraining.
the class StreamTopologyBuilderTest method setup.
@BeforeEach
public void setup() {
// TODO: create the test driver
StreamTopologyBuilder builder = new StreamTopologyBuilder();
testDriver = new TopologyTestDriver(builder.buildTopology());
// TODO: Create test topics
wattsStream = testDriver.createInputTopic("turbine-generated-watts", new IntegerSerializer(), new IntegerSerializer());
ObjectMapperSerde<MWattsMeasurement> measurementSerde = new ObjectMapperSerde<>(MWattsMeasurement.class);
measurementsStream = testDriver.createOutputTopic("turbine-generated-mwatts", new IntegerDeserializer(), measurementSerde.deserializer());
}
Aggregations