use of com.icthh.xm.ms.entity.domain.kafka.SystemEvent in project xm-ms-entity by xm-online.
the class ProfileEventProducer method buildSystemEvent.
private SystemEvent buildSystemEvent(String eventType) {
SystemEvent event = new SystemEvent();
event.setEventId(MdcUtils.getRid());
event.setMessageSource(appName);
event.setEventType(eventType);
event.setTenantKey(TenantContextUtils.getRequiredTenantKeyValue(tenantContextHolder));
event.setUserLogin(authContextHolder.getContext().getRequiredLogin());
event.setStartDate(Instant.now().toString());
return event;
}
use of com.icthh.xm.ms.entity.domain.kafka.SystemEvent in project xm-ms-entity by xm-online.
the class ProfileEventProducer method createEventJson.
/**
* Build message content for kafka's event.
*
* @param profile data for kafka message content
* @param eventType event type for kafka message content
* @return event content
*/
// FIXME must not be public: this is internal implementation protocol
public String createEventJson(Profile profile, String eventType) {
SystemEvent event = null;
try {
event = buildSystemEvent(eventType);
event.setData(buildDataContent(profile));
return mapper.writeValueAsString(event);
} catch (JsonProcessingException e) {
log.warn("Event creation error, eventType = {}, data = {}", eventType, event.getData(), e);
}
return null;
}
use of com.icthh.xm.ms.entity.domain.kafka.SystemEvent in project xm-ms-entity by xm-online.
the class SystemQueueConsumer method consumeEvent.
/**
* Consume system event message.
*
* @param message the system event message
*/
@Retryable(maxAttemptsExpression = "${application.retry.max-attempts}", backoff = @Backoff(delayExpression = "${application.retry.delay}", multiplierExpression = "${application.retry.multiplier}"))
public void consumeEvent(ConsumerRecord<String, String> message) {
MdcUtils.putRid();
try {
log.info("Consume event from topic [{}]", message.topic());
ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
mapper.registerModule(new JavaTimeModule());
try {
SystemEvent event = mapper.readValue(message.value(), SystemEvent.class);
log.info("Process event from topic [{}], {}", message.topic(), event);
if (StringUtils.isBlank(event.getTenantKey())) {
log.info("Event ignored due to tenantKey is empty {}", event);
return;
}
init(event.getTenantKey(), event.getUserLogin());
systemConsumerService.acceptSystemEvent(event);
} catch (IOException e) {
log.error("System queue message has incorrect format: '{}'", message.value(), e);
}
} finally {
destroy();
}
}
use of com.icthh.xm.ms.entity.domain.kafka.SystemEvent in project xm-ms-entity by xm-online.
the class SystemEventMapperUnitTest method createEvent.
private SystemEvent createEvent() {
SystemEvent event = createEventWithoutDates();
event.getDataMap().put(Constants.CREATED_DATE, DEFAULT_CREATED_DATE.toString());
event.getDataMap().put(Constants.LAST_MODIFIED_DATE, DEFAULT_LAST_MODIFIED_DATE.toString());
return event;
}
use of com.icthh.xm.ms.entity.domain.kafka.SystemEvent in project xm-ms-entity by xm-online.
the class SystemEventUnitTest method testToString.
@Test
public void testToString() {
SystemEvent event = new SystemEvent();
event.setData("data");
event.setEventId("eventId");
event.setEventType("eventType");
event.setMessageSource("messageSource");
event.setStartDate("2017-11-21T09:14:35.826Z");
event.setTenantKey("tenantKey");
event.setUserLogin("userLogin");
String result = event.toString();
assertTrue(result.contains("eventId"));
assertTrue(result.contains("eventType"));
assertTrue(result.contains("messageSource"));
assertFalse(result.contains("data"));
assertFalse(result.contains("startDate"));
assertFalse(result.contains("tenantKey"));
assertFalse(result.contains("userLogin"));
}
Aggregations