use of io.muoncore.newton.eventsource.EventTypeNotFound in project newton by muoncore.
the class MuonClusterAwareTrackingSubscriptionManager method localTrackingSubscription.
private void localTrackingSubscription(String subscriptionName, String streamName, Consumer<NewtonEvent> onData, Consumer<Throwable> onError) {
EventStreamIndex eventStreamIndex = getEventStreamIndex(subscriptionName, streamName);
Long lastSeen = eventStreamIndex.getLastSeen() + 1;
log.info("Subscribing from index {} to event stream {} '{}'", lastSeen, subscriptionName, streamName);
Map args = new HashMap();
args.put("from", lastSeen);
args.put("sub-name", subscriptionName);
eventClient.replay(streamName, EventReplayMode.REPLAY_THEN_LIVE, args, new EventSubscriber(event -> {
log.trace("Store is {}, event is {}, time is {}", eventStreamIndexStore, event, event.getOrderId());
Class<? extends NewtonEvent> eventType = MuonLookupUtils.getDomainClass(event);
if (log.isTraceEnabled()) {
log.trace("Store is {}, event is {}, time is {}", eventStreamIndexStore, event, event.getOrderId());
}
eventStreamIndexStore.save(new EventStreamIndex(subscriptionName, event.getOrderId() == null ? 0l : event.getOrderId()));
NewtonEvent newtonEvent;
if (eventType == null) {
newtonEvent = new EventTypeNotFound(event.getOrderId(), event);
} else {
newtonEvent = MuonLookupUtils.decorateMeta(event.getPayload(eventType), event);
}
worker.execute(() -> {
eventStreamProcessor.executeWithinEventContext(newtonEvent, onData);
});
}, onError));
}
Aggregations