NB: Exact replica from the book: Asynchronous Event Handling Using Microservices and Kafka
In this milestone:
- a Go microservice was created called Order
- a Go function for publishing events to a Kafka topic was created called PublishEvent
I was able to test all of the code created in this milestone on my local machine. The instructions below assume you are running on your local machine. I implemented this on a Mac, so references to the command-line will show as a UNIX shell.
- Kafka and Zookeeper need to be running
- The OrderReceived topic should be created
- The Order service needs to be running (assumes you are in the
milestone2/code
folder)- If this is the first time you are running this code, you will need to setup Go modules
- In your
~/.bash_profile
, make sure you have the following ENV var set:export GO111MODULE=on
and make sure the file is sourced. - Initialize Go modules
$ go mod init
$ go mod tidy
- In your
- Run the Order service
$ go run order/main.go
- If this is the first time you are running this code, you will need to setup Go modules
- Send a HTTP request to the order service:
$ curl -v -H "Content-Type: application/json" -d '{"id":"6e042f29-350b-4d51-8849-5e36456dfa48","products":[{"productCode":"12345","quantity":2}],"customer":{"firstName":"Tom","lastName":"Hardy","emailAddress":"[email protected]","shippingAddress":{"line1":"123 Anywhere St","city":"Anytown","state":"AL","postalCode":"12345"}}}' http://localhost:8080/orders
- You should see output in the console of the order service, and no errors. You can also check the contents of the OrderReceived topic in Kafka.
$ $KAFKA_HOME/bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic OrderReceived --from-beginning