
org.reactivecommons.async.starter.senders.GenericDomainEventBus Maven / Gradle / Ivy
package org.reactivecommons.async.starter.senders;
import io.cloudevents.CloudEvent;
import lombok.RequiredArgsConstructor;
import org.reactivecommons.api.domain.DomainEvent;
import org.reactivecommons.api.domain.DomainEventBus;
import org.reactivecommons.async.starter.exceptions.InvalidConfigurationException;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
import java.util.concurrent.ConcurrentMap;
import static org.reactivecommons.async.api.HandlerRegistry.DEFAULT_DOMAIN;
@RequiredArgsConstructor
public class GenericDomainEventBus implements DomainEventBus {
private final ConcurrentMap domainEventBuses;
@Override
public Publisher emit(DomainEvent event) {
return emit(DEFAULT_DOMAIN, event);
}
@Override
public Publisher emit(String domain, DomainEvent event) {
DomainEventBus domainEventBus = domainEventBuses.get(domain);
if (domainEventBus == null) {
return Mono.error(() -> new InvalidConfigurationException("Domain not found: " + domain));
}
return domainEventBus.emit(event);
}
@Override
public Publisher emit(CloudEvent event) {
return emit(DEFAULT_DOMAIN, event);
}
@Override
public Publisher emit(String domain, CloudEvent event) {
DomainEventBus domainEventBus = domainEventBuses.get(domain);
if (domainEventBus == null) {
return Mono.error(() -> new InvalidConfigurationException("Domain not found: " + domain));
}
return domainEventBus.emit(event);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy