eiffel-community/eiffel-intelligence

NullPointerException thrown if meta.id is not found in a consumed event

Opened this issue · 1 comments

Description

EventHandler throwns a NullPointerException if the meta.id field is not found in consumed event. This can be done better with the event being ignored and better message in the log.
There is no actual validation of the event with a schema and it is this way by design to allow technically any type of protocol.

Motivation

A better explanation in the log.

Exemplification

Benefits

Possible Drawbacks

The class EventHandler contains the method onMessage, where this bug needs to be fixed.

    @Async
    public void onMessage(Message message, Channel channel) throws Exception {
        String messageBody = new String(message.getBody());
        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode node = objectMapper.readTree(messageBody);
        String id = node.get("meta").get("id").toString();
        String port = environment.getProperty("local.server.port");
        Thread.currentThread().setName(Thread.currentThread().getName() + "-" + port);
        LOGGER.debug("Thread id {} spawned for EventHandler on port: {}", Thread.currentThread().getId(), port);
        LOGGER.debug("Event {} received on port {}", id, port);

It would be nice if line 4 could be broken out to a separate method. (Makes it easier to test)