use of com.kloia.eventapis.common.Context in project eventapis by kloiasoft.
the class EventMessageConverter method extractAndConvertValue.
@Override
public Object extractAndConvertValue(ConsumerRecord<?, ?> record, Type type) {
Object value = record.value();
if (value instanceof PublishedEventWrapper) {
PublishedEventWrapper eventWrapper = (PublishedEventWrapper) value;
Context context = eventWrapper.getContext();
context.setCommandContext(record.topic());
operationContext.switchContext(context);
userContext.extractUserContext(eventWrapper.getUserContext());
try {
return objectMapper.readValue(eventWrapper.getEvent(), TypeFactory.rawClass(type));
} catch (IOException e) {
operationRepository.failOperation(operationContext.getCommandContext(), event -> event.setEventState(EventState.TXN_FAILED));
throw new SerializationException(e);
}
} else
return super.extractAndConvertValue(record, type);
}
Aggregations