Lets say I’m tracking deliveries. Where the message for each delivery is:
input
topic: deliveries
key: deliveryId
value: { driver: ‘John Doe’, status: ‘delivering’, location: ‘latlong’ }
I’d like to have a projection which produces a list of all deliveries with the statuses ‘collecting’ or ‘delivering’:
output
topic: activeDeliveries
value: [
{ deliveryId: 12345, driver: ‘John Doe’, status: ‘delivering’, location: ‘latlong’ },
{ deliveryId: 12346, driver: ‘Jane Doe’, status: ‘collecting’, location: ‘latlong’ }
]
How do I produce this list using the Kafka Streams DSL?
It seems as though I want a table of deliveries. When any one of the deliveries change their status or location it’ll update the table then reproject the list to activeDeliveries.
output
topic: activeDeliveries
value: [
{ deliveryId: 12345, driver: ‘John Doe’, status: ‘delivering’, location: ‘latlong’ },
{ deliveryId: 12346, driver: ‘Jane Doe’, status: ‘delivering’, location: ‘latlong’ }
]
Then when a delivery is complete it’ll be removed from the table. (Will need to use null values to remove)
output
topic: activeDeliveries
value: [
{ deliveryId: 12345, driver: ‘John Doe’, status: ‘delivered’, location: ‘latlong’ }, < will be removed
{ deliveryId: 12346, driver: ‘Jane Doe’, status: ‘delivering’, location: ‘latlong’ }
]
In other words - can I just output a stream of the whole table when any of the rows change?