Source code examples and demo from Mark Richards microservices caching session at NFJS.
See the demo folder for a recording.
The presentation slides are available here.
Run the RabbitMQ server:
docker run -p 5672:5672 -d --hostname my-rabbit --name some-rabbit rabbitmq:3
To setup all of the exchanges, queues, and bindings used by these examples, run the following:
./gradlew initQueue
The DataWriter receives update requests over the datapump.q
queue and simulates a slow operation such as writing to a backend data store.
./gradlew runDataWriter
CustomerInfoService consumes client requests to update the name. Each service instance listens for update events over the queue name.q
. When an event occurs, an distributed in-memory cache is updated first. The hazlecast distributed in-memory cache updates the memory of the other service instances currently running. In addition, the name update is routed to the DataWriter
for persistent storage over the datapump.q
queue.
Open a new terminal and run the following to start the service and initialize the cache:
./gradlew runService --args load
Open two new terminals run the following in each:
./gradlew runService
Run the following multiple times each with a different placeholder value for the argument:
./gradlew update --args <Name>
The following command examines the queues inside the RabbitMQ server:
watch docker exec some-rabbit rabbitmqctl list_queues