The petstore is an example application built on Micronaut in the form of Microservices architecture. The features of the application will be familiar to the Java community where pet profiles are displayed. Users can see a list of pets and enter a comment about the pets. Vendors are selling pets for a price and also notifications by email are included.
The purpose of the petstore application is to demonstrate how Micronaut can be utilized in a Microservice architecture. Each application has its own database, project structure, build cycle and resulting artifact. In order to demonstrate the ability of Micronaut to integrate with different technologies, the example is wired to various database implementations and developed with various programming languages.
The architecture of the pet store begins with the
frontend project, which is the UI to the application. The
communicate with the
storefront project, which acts s a gateway to the rest of the Microservice applications. The Microservice
applications are broken up by cohesive functionality. For example
pets will focus on the displaying and storing pets, where
vendors will do the same for vendors.
Consul is used for service discovery of each Microservice provider. Each Microservice
can subsequently communicate with each other through
See the diagram below:
In the case you want Micronaut installed locally, go the Micronaut root folder and use gradle to install the Micronaut framework dependencies into local maven.
Using docker can help get the application up and running quite quickly.
Running Consul and Databases
consul needs to be running on port 8500.
mongo needs to be running on port 27017.
neo4j needs to be running on port 7687.
redis needs to be running on port 6379.
With docker you can start them all up in a container:
docker-compose up consul mongodb neo4j redis
Running Application with Gradle
The applications depend on one another so gradle builds need to be run in order:
./gradlew pets:run ./gradlew vendors:run
Once those are running start the following individually or as a group.
./gradlew comments:run mail:run offers:run --parallel
Finally run the
frontend, which is written with
Running Application with Docker
The application is easily built and run in a docker container with the command below. However, note you will not be able to debug with breakpoints etc (a really handy way to learn Micronaut).
./gradlew build -x test docker-compose build docker-compose up
Wait till all the applications register with consul.
You may seen some errors during applications startup like
ERROR i.m.d.registration.AutoRegistration - Error reporting passing state to Consul: Internal Server Error. They happen some time and they depend on the computer you're running docker-compose. They
are due to the high CPU usage because a lot of containers are starting at the same time. The applications will try to register
itself in Consul automatically after a moment and everything will work as expected.
Access the app at http://localhost:3000/.
Note that if using a windows version of docker (specifically pre Windows 10 Pro) that
localhostwill be referred to as
Most Windows users will need to set up Docker Toolbox for Windows in order to use Docker. As a result, the default ip becomes
192.168.99.100. This adds the complication that for any application, consul, or database created in a docker container,
needs to be replaced with the docker-machine ip.
The recommended setup to demo the petstore application on Windows is to do the following operations in order, while in the
- Replace petstore configuration that references
192.168.99.100(or the result of running
docker-machine ip). Search for configurations that are referring to systems created in a docker container (those generated by the next step below).
- docker-compose up consul mongodb neo4j redis
- gradlew pets:run
- gradlew vendors:run
- gradlew comments:run mail:run offers:run --parallel
- gradlew storefront:run
- gradlew frontend:react:start