...
Then, it is possible to implement listeners for both events versions.
Code Block | ||||
---|---|---|---|---|
| ||||
/**
* Consume event from v0 schema.
*/
public void consume(final org.onap.cps.event.model.v0.CpsDataUpdatedEvent eventV0) {
// Map event v0 to v1
org.onap.cps.event.model.v1.CpsDataUpdatedEvent eventV1 = this.cpsDataUpdatedEventMapper.eventV0ToEventV1(eventV0);
// Consume event v1
consume(eventV1);
}
/**
* Consume event from v1 schema.
*/
public void consume(final org.onap.cps.event.model.v1.CpsDataUpdatedEvent eventV1) {
// Map event to entity
final var networkData = this.cpsDataUpdatedEventMapper.eventToEntity(eventV1);
// Persist entity
this.networkDataService.addNetworkData(networkData);
}
|
The mapper implemented to convert v0 events into v1 has some logic depending on the change made in the schema. If new fields are added, they might be given a default value if possible.