Kafka Projection Updates Configuration
Overview
The Kafka Projection Updates is a JSON file (kafkaProjectionUpdates.json
) which describes for each projection a Projection Updates topic and a Strategy to generate the projection changes identifier. This file is typically used by the Real Time Updater and the Single View Trigger Generator to send the Projection Updates message to te right topic and apply the right Strategy.
Syntax
The Kafka Projection Updates is made of the following fields
{
"PROJECTION_NAME": {
"updatesTopic": "PROJECTION_UPDATE_TOPIC",
"strategy": "STRATEGY"
}
}
PROJECTION_NAME
: Name of the collection of the projectionupdatesTopic
: The topic where the Projection Updates messages are sent, if you haven't created a topic for the projection yet take a look to our naming conventions for the Projection Updates topics.strategy
: Strategy you want to use onto this projection. You can choose between__automatic__
,__lookup__
and__fromFile__
__automatic__
: The automatic strategy handles the generation of the projection changes identifier automatically. This is the preferred method and in most cases it will be enough for your Strategy executions.__lookup__
: The lookup Strategy means the Projection Updates will be handled by the Single View Patch method. So before using this value make sure you have correctly configured all the parts for the Single View Patch architecture in your project.__fromFile__
: This lets you specify a Javascript file path which will execute the a custom Strategy on the Projection Updates message and return an array of projection change identifiers. This is the most customizable option and should only be used when the__automatic__
Strategy is not enough for your case.
The __fromFile__
Strategy expects a path to a Javascript file, like so __fromFile__[CUSTOM_STRATEGY.js]
. This Javascript file should export a default async generator function with the following parameters:
strategyContext
: Strategy context object composed of two properties:logger
: Pino logger to print out useful service logsdbMongo
: the configured MongoDB Database instance where the projections are stored
updateEvent
: The Projection Updates message.
Here's an example of what that file could look like (let's say our CUSTOM_STRATEGY
is called myCustomStrategy
):
// note: this has to be an AsyncGenerator
module.exports = async function* myCustomStrategy ({ logger, dbMongo }, updateEvent) {
yield { IDENTIFIER_FIELD: updateEvent.after.FIELD }
}