use of io.openk9.sql.api.event.EntityEvent in project openk9 by smclab.
the class DatasourceEventPublisher method _publishEvent.
private Publisher<Void> _publishEvent(EntityEvent<?> entityEvent) {
return Mono.defer(() -> {
String entityName = entityEvent.getEntityClass().getSimpleName();
String eventType = entityEvent.getType().name();
String routingKey = _createRoutingKey(_routingKeyTemplate, eventType, entityName);
String bodyJson = _jsonFactory.toJson(entityEvent.getValue());
if (_log.isDebugEnabled()) {
_log.debug("message published. " + "exchange: " + _exchange + " " + "routingKey: " + routingKey + " " + "message: " + bodyJson);
}
OutboundMessage outboundMessage = _outboundMessageFactory.createOutboundMessage(builder -> builder.exchange(_exchange).routingKey(routingKey).body(bodyJson.getBytes()));
return _senderReactor.sendMono(Mono.just(outboundMessage));
});
}
use of io.openk9.sql.api.event.EntityEvent in project openk9 by smclab.
the class DriverManagerActivator method activate.
@Activate
public void activate(Config config) throws SchedulerError {
Disposable disposable1 = _datasourceRepository.findAll(true).concatMap(this::_schedule).subscribe();
Disposable disposable2 = _entityEventBus.stream().filter(e -> e.getEntityClass() == Datasource.class).concatMap(entityEvent -> {
Datasource datasource = (Datasource) entityEvent.getValue();
if (entityEvent instanceof EntityEvent.UpdateEvent || entityEvent instanceof EntityEvent.InsertEvent) {
return _schedule(datasource);
} else {
return Mono.fromRunnable(() -> _scheduler.unschedule(_PREFIX + datasource.getName()));
}
}).subscribe();
_autoClosableSafe = AutoCloseables.mergeAutoCloseableToSafe(disposable1::dispose, disposable2::dispose);
}
Aggregations