Adapting an account service to new requirements
An account service is the main consumer we need to implement for the given context. First, we need to have the ability to interact with Apache Kafka. Just copy the already implemented account microservice and continue working on that. Navigate to Ch07/accountService
and run the following command to install the kafkajs
package:
npm install kafkajs
Now we need to develop a separate module to work with Apache Kafka. Apache Kafka has its variables (brokers, topics, etc.) and that is why we use a .env
file as we did for the transaction service. Under the accountService
folder, we have configs/.env
, and we added the following config items:
#KAFKA Configuration KAFKA_CLIENT_ID=account-service KAFKA_BROKERS=localhost:29092 KAFKA_TOPIC=transaction-service-topic KAFKA_GROUP_ID=account-group
To read the .env
file, we use a special configuration that lives under src/config
and is called config.js
. But we need to add the required changes...