Implementing the earthquake stream consumer
Producing is not very valuable if you don’t have a consumer to consume data. Our second microservice, called earthquakeConsumer
, is going to consume data from Apache Kafka. It has a similar code structure to our streaming API (Figure 8.5).
Figure 8.5: Earthquake consumer API structure
Let’s start from the configs
folder. As in our first microservice in Chapter 5, we have a .env
file inside the folder. The responsibility of this folder is to store relevant configurations. Here is what it looks like:
PORT=3002 #KAFKA Configuration KAFKA_CLIENT_ID=earthquake-consumer-service KAFKA_BROKERS=localhost:29092 KAFKA_TOPIC=earthquake-service-topic KAFKA_GROUP_ID=earthquake-consumer-group
We introduced an additional configuration, KAFKA_GROUP_ID
, which identifies the consumer group, allowing Kafka to balance partition assignments among consumers. It is a string property used to identify a collection of...