Read the individual events from a Kafka topic called input-messages
Validate the message, sending any defective event to a dedicated Kafka topic called invalid-messages
Enrich the message with the geographic location data
Write the enriched messages in a Kafka topic called valid-messages
xxxxxxxxxx
package monedero;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.maxmind.geoip.Location;
import monedero.extractors.GeoIPService;
import org.apache.kafka.clients.producer.KafkaProducer;
import java.io.IOException;
public final class Enricher implements Producer {
private final KafkaProducer<String, String> producer;
private final String validMessages;
private final String invalidMessages;
private static final ObjectMapper MAPPER = new ObjectMapper();
public Enricher(String servers, String validMessages, String
invalidMessages) {
this.producer = new KafkaProducer<>
(Producer.createConfig(servers));
this.validMessages = validMessages;
this.invalidMessages = invalidMessages;
}
@Override
public void process(String message) {
try {
// this method below is filled below
} catch (IOException e) {
Producer.write(this.producer, this.invalidMessages, "{\"error\": \""
+ e.getClass().getSimpleName() + ": " + e.getMessage() + "\"}");
}
}
}
https://www.ibm.com/docs/en/ftmfm/4.0.3?topic=scenarios-message-enrichment