Search in sources :

Example 1 with EntityEvent

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));
    });
}
Also used : OutboundMessage(io.openk9.ingestion.api.OutboundMessage)

Example 2 with EntityEvent

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);
}
Also used : Disposable(reactor.core.Disposable) Datasource(io.openk9.model.Datasource) SchedulerEnabledDTO(io.openk9.plugin.driver.manager.model.SchedulerEnabledDTO) Logger(org.slf4j.Logger) Disposable(reactor.core.Disposable) Datasource(io.openk9.model.Datasource) Deactivate(org.osgi.service.component.annotations.Deactivate) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) Mono(reactor.core.publisher.Mono) Scheduler(org.apache.karaf.scheduler.Scheduler) AutoCloseables(io.openk9.osgi.util.AutoCloseables) ScheduleOptions(org.apache.karaf.scheduler.ScheduleOptions) Component(org.osgi.service.component.annotations.Component) SchedulerError(org.apache.karaf.scheduler.SchedulerError) DatasourceRepository(io.openk9.datasource.repository.DatasourceRepository) Map(java.util.Map) PluginDriverManagerClient(io.openk9.plugin.driver.manager.client.api.PluginDriverManagerClient) Activate(org.osgi.service.component.annotations.Activate) Reference(org.osgi.service.component.annotations.Reference) EntityEvent(io.openk9.sql.api.event.EntityEvent) EntityEventBus(io.openk9.sql.api.event.EntityEventBus) Job(org.apache.karaf.scheduler.Job) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

DatasourceRepository (io.openk9.datasource.repository.DatasourceRepository)1 OutboundMessage (io.openk9.ingestion.api.OutboundMessage)1 Datasource (io.openk9.model.Datasource)1 AutoCloseables (io.openk9.osgi.util.AutoCloseables)1 PluginDriverManagerClient (io.openk9.plugin.driver.manager.client.api.PluginDriverManagerClient)1 SchedulerEnabledDTO (io.openk9.plugin.driver.manager.model.SchedulerEnabledDTO)1 EntityEvent (io.openk9.sql.api.event.EntityEvent)1 EntityEventBus (io.openk9.sql.api.event.EntityEventBus)1 Date (java.util.Date)1 Map (java.util.Map)1 Job (org.apache.karaf.scheduler.Job)1 ScheduleOptions (org.apache.karaf.scheduler.ScheduleOptions)1 Scheduler (org.apache.karaf.scheduler.Scheduler)1 SchedulerError (org.apache.karaf.scheduler.SchedulerError)1 Activate (org.osgi.service.component.annotations.Activate)1 Component (org.osgi.service.component.annotations.Component)1 Deactivate (org.osgi.service.component.annotations.Deactivate)1 Reference (org.osgi.service.component.annotations.Reference)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1