...
Code Block |
---|
title | V1NotificationService.java |
---|
linenumbers | true |
---|
|
@Service("v1NotificationService")
public class V1NotificationService extends NotificationService {
private final V1NotificationPublisher notificationPublisher;
...
@Override
protected void notify(final String dataspaceName, final String anchorName) {
final var cpsDataUpdatedEvent =
super.getCpsDataUpdatedEventFactory().createCpsDataUpdatedEventV1(dataspaceName, anchorName);
notificationPublisher.sendNotification(cpsDataUpdatedEvent);
}
} |
...
Code Block |
---|
title | V1NotificationPublisher.java |
---|
linenumbers | true |
---|
|
import org.onap.cps.event.model.v1.CpsDataUpdatedEvent;
public class V1NotificationPublisher extends NotificationPublisher<CpsDataUpdatedEvent> {
public V1NotificationPublisher(
final KafkaTemplate<String, CpsDataUpdatedEvent> kafkaTemplate,
final @Value("${notification.data-updated.topic}") String topicName) {
super(kafkaTemplate, topicName);
}
protected void sendNotification(@NonNull final CpsDataUpdatedEvent cpsDataUpdatedEvent) {
final var messageKey =
cpsDataUpdatedEvent.getContent().getDataspaceName() + "," + cpsDataUpdatedEvent.getContent().getAnchorName();
super.getKafkaTemplate().send(super.getTopicName(), messageKey, cpsDataUpdatedEvent);
}
} |
Runtime Configuration
The event schema version to be published is specified and configurable in application properties. The specified value is used by Spring when the application is starting to instantiate the expected concrete classes for Notification Service and Publisher.
Code Block |
---|
language | yml |
---|
title | application.yml |
---|
linenumbers | true |
---|
|
notification:
data-updated:
enabled: false
topic: ${CPS_CHANGE_EVENT_TOPIC:cps.cfg-state-events}
event-schema-version: ${CPS_CHANGE_EVENT_SCHEMA_VERSION:v1} |
The specific requested Notification Service is injected into Data Service:
Code Block |
---|
title | CpsDataServiceImpl.java |
---|
linenumbers | true |
---|
|
public class CpsDataServiceImpl implements CpsDataService {
...
@Value("${notification.event-schema-version}NotificationService")
private String notificationServiceQualifier;
private NotificationService notificationService;
@Autowired
public void setNotificationService(final ApplicationContext applicationContext) {
this.notificationService = (NotificationService) applicationContext.getBean(notificationServiceQualifier);
}
...
} |