Skip to main content
Version: 11.7.x

Kafka Projection Updates Configuration

Overview

The Kafka Projection Updates is a JSON file 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.

Configuration Properties

The Kafka Projection Updates is made of the following fields:

  • PROJECTION_NAME: Name of the collection of the projection
  • updatesTopic: 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__ and __fromFile__
Projection Updates Configuration

kafkaProjectionUpdates.json
{
"PROJECTION_NAME": {
"updatesTopic": "PROJECTION_UPDATE_TOPIC",
"strategy": "STRATEGY"
}
}

There will be different behaviors based on the strategy value:

  • __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.

  • __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. This 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 logs
      • dbMongo: 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):

    Custom Strategy

    // note: this has to be an AsyncGenerator
    module.exports = async function* myCustomStrategy ({ logger, dbMongo }, updateEvent) {
    yield { IDENTIFIER_FIELD: updateEvent.after.FIELD }
    }