1. MessagingRun6ARebuildDemo
src/main/java/com/example/messaging/run6a/demo/MessagingRun6ARebuildDemo.javaErzeugt Commands und Events, publiziert sie und lässt den Consumer die Projektion aktualisieren.
- Typ
- class MessagingRun6ARebuildDemo
- Verwendet
- EventSchemaRegistry, InMemoryKafkaBroker, BillingProjectionConsumer, IdempotencyStore
- Verwendet von
- —
- Einstiege
- main(String[] args)
package com.example.messaging.run6a.demo;
import com.example.messaging.run6a.broker.InMemoryKafkaBroker;
import com.example.messaging.run6a.consumer.BillingProjectionConsumer;
import com.example.messaging.run6a.consumer.DeadLetterQueue;
import com.example.messaging.run6a.consumer.IdempotencyStore;
import com.example.messaging.run6a.model.EventFactory;
import com.example.messaging.run6a.schema.EventSchemaRegistry;
public final class MessagingRun6ARebuildDemo {
public static void main(String[] args) {
InMemoryKafkaBroker broker = new InMemoryKafkaBroker();
broker.createTopic("order-events", 3);
EventFactory factory = new EventFactory();
broker.publish("order-events", factory.orderPlaced("trace-1", "ORD-100", "C-1", 12_990, "EUR", 2));
broker.publish("order-events", factory.orderPlaced("trace-2", "ORD-101", "C-2", 7_500, "EUR", 2));
BillingProjectionConsumer billing = new BillingProjectionConsumer(
new EventSchemaRegistry().register("OrderPlaced", 1, 2),
new IdempotencyStore(),
new DeadLetterQueue());
broker.poll("order-events", "billing-group", 10).forEach(record -> {
billing.handle(record.event());
broker.commit(record.topic(), "billing-group", record.partition(), record.offset() + 1);
});
System.out.println("RUN6A_REBUILD_DEMO_OK projectionCount=" + billing.projectionCount() + " lag=" + broker.lag("order-events", "billing-group"));
}
}