Search in sources :

Example 1 with SystemEvent

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;
}
Also used : SystemEvent(com.icthh.xm.ms.entity.domain.kafka.SystemEvent)

Example 2 with SystemEvent

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;
}
Also used : SystemEvent(com.icthh.xm.ms.entity.domain.kafka.SystemEvent) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with SystemEvent

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();
    }
}
Also used : SystemEvent(com.icthh.xm.ms.entity.domain.kafka.SystemEvent) JavaTimeModule(com.fasterxml.jackson.datatype.jsr310.JavaTimeModule) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Retryable(org.springframework.retry.annotation.Retryable)

Example 4 with SystemEvent

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;
}
Also used : SystemEvent(com.icthh.xm.ms.entity.domain.kafka.SystemEvent)

Example 5 with SystemEvent

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"));
}
Also used : SystemEvent(com.icthh.xm.ms.entity.domain.kafka.SystemEvent) Test(org.junit.Test)

Aggregations

SystemEvent (com.icthh.xm.ms.entity.domain.kafka.SystemEvent)8 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JavaTimeModule (com.fasterxml.jackson.datatype.jsr310.JavaTimeModule)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1 Retryable (org.springframework.retry.annotation.Retryable)1