use of io.eventuate.local.common.exception.EventuateLocalPublishingException in project eventuate-local by eventuate-local.
the class DbLogBasedCdcKafkaPublisher method handleEvent.
@Override
public void handleEvent(EVENT publishedEvent) throws EventuateLocalPublishingException {
Objects.requireNonNull(publishedEvent);
logger.trace("Got record " + publishedEvent.toString());
String aggregateTopic = publishingStrategy.topicFor(publishedEvent);
String json = publishingStrategy.toJson(publishedEvent);
Exception lastException = null;
for (int i = 0; i < 5; i++) {
try {
if (duplicatePublishingDetector.shouldBePublished(publishedEvent.getBinlogFileOffset(), aggregateTopic)) {
producer.send(aggregateTopic, publishingStrategy.partitionKeyFor(publishedEvent), json).get(10, TimeUnit.SECONDS);
publishingStrategy.getCreateTime(publishedEvent).ifPresent(time -> histogramEventAge.ifPresent(x -> x.set(System.currentTimeMillis() - time)));
meterEventsPublished.ifPresent(Counter::increment);
databaseOffsetKafkaStore.save(publishedEvent.getBinlogFileOffset());
} else {
logger.debug("Duplicate event {}", publishedEvent);
meterEventsDuplicates.ifPresent(Counter::increment);
}
return;
} catch (Exception e) {
logger.warn("error publishing to " + aggregateTopic, e);
meterEventsRetries.ifPresent(Counter::increment);
lastException = e;
try {
Thread.sleep((int) Math.pow(2, i) * 1000);
} catch (InterruptedException ie) {
throw new RuntimeException(ie);
}
}
}
throw new EventuateLocalPublishingException("error publishing to " + aggregateTopic, lastException);
}
use of io.eventuate.local.common.exception.EventuateLocalPublishingException in project eventuate-local by eventuate-local.
the class PollingCdcKafkaPublisher method handleEvent.
@Override
public void handleEvent(EVENT event) throws EventuateLocalPublishingException {
logger.trace("Got record " + event.toString());
String aggregateTopic = publishingStrategy.topicFor(event);
String json = publishingStrategy.toJson(event);
Exception lastException = null;
for (int i = 0; i < 5; i++) {
try {
producer.send(aggregateTopic, publishingStrategy.partitionKeyFor(event), json).get(10, TimeUnit.SECONDS);
publishingStrategy.getCreateTime(event).ifPresent(time -> histogramEventAge.ifPresent(x -> x.set(System.currentTimeMillis() - time)));
meterEventsPublished.ifPresent(Counter::increment);
return;
} catch (Exception e) {
logger.warn("error publishing to " + aggregateTopic, e);
meterEventsRetries.ifPresent(Counter::increment);
lastException = e;
try {
Thread.sleep((int) Math.pow(2, i) * 1000);
} catch (InterruptedException ie) {
throw new RuntimeException(ie);
}
}
}
throw new EventuateLocalPublishingException("error publishing to " + aggregateTopic, lastException);
}
Aggregations