To create a projection, you should create a System of Records. This is the data source which updates the projections.
To do so, open the Projections section in the fast data group of Mia-Platform Console. Then, select the create button.
The creation of a System of Records requires you to insert a system ID, useful to recognize the system.
To delete a System of Records, you have to click the Delete button at the bottom-right corner of the System of Records detail page.
The deletion is not allowed until you have at least one Projection inside the System, hence you need to delete all the projections in a System before being able to delete it.
When a projection is updated, the Real-Time Updater changes a collection called, by default,
SYSTEM_ID is the name of the System of Records which the Real-Time Updater belongs to. It inserts into it the information about the updated document.
The default Projection Changes collection is automatically managed by the Console and it does not support the utilization of custom indexes. If you need to take advantage of them to speed up your queries, you need to use a custom projection changes collection.
One Projections Changes collection is created for each System of Records as default.
This collection will be used by the Single View Creator to know which single view needs an update. It is the connection between projections and single view.
You can choose to use a collection you have already created in the CRUD section through advanced configuration. To do that, read here.
When you delete a System of Records, the Projections Changes collection linked to it will be deleted as well, because it is no more useful.
This will not happen if you have chosen to use your own custom Projections Changes collection through the advanced section.
To create a projection using the Console, select the System of Records from which the projection is taken.
In the System of Records detail, search for the
Projections card and click on the create button.
Here, you can insert the name of your projection.
The projection name is used as MongoDB collection name.
To view the details of a projection, click on the arrow button at the end of the table row.
Once in the projection detail page, there is a card with detail of
Here, you can modify the default name of the topics per environment.
The topics names are pre-compiled with our suggested name:
projectionName are filled with, respectively, the id of the console project, the id of the associated environment and the name of the projection.
A projection has the predefined collection properties which are required for the
Crud Service, which is the service responsible for creating the collection on MongoDB.
These fields cannot be deleted and only the
_id field is editable. You cannot add custom fields to the metadata.
These fields have no
Cast function assigned because they are not used for mapping of fields from the Kafka Message received. This means that if the Kafka Message contains a field with the same name as one of the metadata fields, it is not copied on the projection.
In the card
Fields in projection, you can add new fields.
Once you click the
Create field button, a form is prompted where you should insert the following fields (all fields are required):
Name: name of the projection field;
Type: one of
Array of object,
Array of number,
Array of string,
Cast function: it shows the possible Cast Function to select for the specified data type;
Required: set the field as required, default to false;
Nullable: declare field as nullable, default to false.
Primary Key: set the field as part of the primary key, default to false.
It's mandatory to set at least one Primary Key for each Projection. Otherwise, you will not be able to save your configuration.
Setting the Primary Keys does not create automatically the unique indexes. You need to create them by yourself.
real-time updater deletes a projection document, it actually makes a virtual delete instead of real document deletion. This means that the document is actually kept in the database, but the
__STATE__ field (one of the default fields of the
Crud Service) is set to
In the card
Fields in projection, you can upload a data sample to generate fields by clicking on the appropriate button. Doing this will replace the current fields with those contained within the file.
The supported file extension are:
At the end of the upload an internal function will try to cast the types correctly, otherwise it will treat them as strings by default.
Import of fields is supported only for the following data types:
Date. For example, you cannot import fields of type object.
You cannot import fields with the same name as one of the metadata fields.
In the card
Indexes, you can add indexes to the collection. To learn more about crud indexes, click here.
However, differently from Indexes that can be created on a normal CRUD, in this section the
Geo index type is not available.
_id index is created by default and it is not deletable.
Both custom fields and metadata can be used as fields for indexes.
In order for the Real Time Updater to correctly update its projections two actions are necessary:
- You should define at least one custom field with flags Primary Key and Required set to true in the
- Then, you should create an index using the previously defined custom field and set to true the index unique flag.
In this way, the Real Time Updater updates the projection document with the correct primary key value instead of creating a new document.
You can expose a projection through API, only with
GET method (the data in the projection are modifiable only by the Real Time Updater service).
To expose the Fast Data projection, create an Endpoint with type
Fast Data Projection linked to the desired projection.
You can expose a projection on a CMS page to help you review the data inside the collection, follow Configure CMS extensions.
The exposed API is not required for Fast Data to work. It is an optional behavior in case you need access to the data without directly accessing it from the database.
Once you have created a System, you need to select the format of the Kafka messages sent from the system.
To do that, you must correctly configure the Kafka Message Adapter. Go to the
Advanced section of the
Design area in Console, open
fast-data from menu and open the
Here, you should write a configuration object as follows:
THE_FORMAT is the format of your Kafka Messages and can be one of the following:
It's the default one.
timestamp of the Kafka message has to be a stringified integer greater than zero. This integer has to be a valid timestamp.
key of the Kafka message has to be a stringified object containing the primary key of the projection, if
value also contains the primary key of the projection this field can be an empty string.
value is null if it's a delete operation, otherwise it contains the data of the projection.
offset is the offset of the kafka message.
Example of a delete operation
Example of an upsert:
timestamp of the Kafka message is a stringified integer greater than zero. This integer has to be a valid timestamp.
offset is the offset of the kafka message.
key can have any valid Kafka
value of the Kafka message instead needs to have the following fields:
op_typeidentifies the type of operation (
Iif insert ,
afterit's the data values after the operation execution (
nullor not set if it's a delete)
beforeit's the data values before the operation execution (
nullor not set if it's an insert)
value for an insert operation:
If you have Kafka Messages that do not match the format above, you can create your own custom adapter for the messages.
To do that, you need to create a
You have to create the adapter function before setting
custom in the advanced file and saving.
This adapter is a function that accepts as arguments the kafka message and the list of primary keys of the projection, and returns an object with the following properties:
- offset: the offset of the kafka message
- timestampDate: an instance of
Dateof the timestamp of the kafka message.
- keyObject: an object containing the primary keys of the projection. It is used to know which projection document needs to be updated with the changes set in the value.
- value: the data values of the projection, or null
value is null, the operation is supposed to be a delete.
keyObject cannot be null.
In order to write your custom Kafka message adapter, first clone the configuration repository: click on the git provider icon in the right side of the header (near to the documentation icon and user image) to access the repository and then clone it.
Your adapter function file needs to be created below a folder named
fast-data-files, if your project does not have it, create it.
In this folder, create a folder named as
For instance if you want to create an adapter for the system
my-system you need to create the following directory tree:
The file should export a simple function with the following signature:
kafkaMessage argument is the kafka message as received from the
key are of type Buffer,
timestamp are of type string.
primaryKeys is an array of strings which are the primary keys of the projection whose topic is linked.
Once you have created your own custom adapter for the Kafka messages, commit and push to load your code on git.
Now you need to go on the Console and save in order to generate the configuration for your
Real Time Updater service that uses the adapter you created.
After any changes you make on the
adapter implementation, you need to save from the Console to update the configuration of the services.
Now that you have committed and pushed your custom adapter function you can set
custom in the advanced file and save.
Replicas ensures that a specified number of pod replicas are running at any given time. It is used to guarantee the availability of a specified number of identical Pods.
If you do not specify replicas, then it defaults to 1.
To know how to set replicas for the Real-Time Updater, read here.
Real-Time Updater has default settings for the CPU and memory requests and limits. These defaults are set at Console installation time. For Console PaaS, these are already set with values:
- Memory Limit: 250Mi
- Memory Request: 80Mi
- CPU Limit: 200m
- CPU Request: 40m
To know the limits on your on-premise Console installation, please contact your Mia Platform referent.
In your custom files (e.g.
kafka-adapters) you can import only the node modules present in the following list:
It is used the node version 12.