Use Kafka to help handle distributed messaging, by using the Event Sourcing pattern that is inherently atomic.
Then, by using a pattern called Command-Query Responsibility Segregation (CQRS), have a materialized view acting as the gate for data retrieval. Finally, learn how to make our consumer redundant by using consumer group. The whole application is delivered in Go.
Microservices allow us to decompose a large, cumbersome application into smaller, more manageable repositories. This allows greater scalability and development speed on each individual microservice.
Atomicity!! How do we deal with distributed data, which is inherent to microservice architecture?
Database :: Kafka
Table:Database :: Topic:Kafka
Row:Table :: Commit Log:Topic
Commit logs are ordered based on offset, where each new message N+1 the offset of the last commit.
- Download and install Kafka. If necessary, also download ZooKeeper independently
- Start Zookeeper server(s)
<path to ZK>/zookeeper-server-start.sh config/zookeeper.properties
- Start Kafka server(s)
<path to kafka>/kafka-server-start.sh config/server.properties
- Create first topic
kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic xbanku-transactions-t2
- Init repo
- Install Govendor for package management and
govendor init
govendor add +external
- Install ginkgo for TDD and Gomeda
go get github.com/onsi/ginkgo/ginkgo
go get github.com/onsi/gomega
ginkgo bootstrap
- Install Govendor for package management and
- Run test suite
ginkgo
- If you have an external Redis URL, set environment variable
REDIS_URL
go build && ./kafkaevents
- Now able to use the producer to produce messages to kafka
create###Cole Bittel Message: {Event:{AccId:0ef305f1-cb00-47db-a0cc-547f1127d00c Type:CreateEvent} AccName:Cole Bittel} Message is stored in partition 0, offset 0
- Can alternative do
--act=consumer
and consumer will process and output all produced messages from beginning of partition
- Test