The next diagram represents the implementation view of the BrownField PSS microservices system:
As shown in the preceding diagram, we are implementing four microservices as an example: Search, Fare, Booking, and Check-in. In order to test the application, there is a website application developed using Spring MVC with Thymeleaf templates. The asynchronous messaging is implemented with the help of RabbitMQ. In this sample implementation, the default H2 database is used as the in-memory store for demonstration purposes.
The code in this section demonstrates all the capabilities highlighted in the Reviewing the microservices capability model section of this chapter.
The basic implementation of the BrownField Airline's PSS microservices system has five core projects as summarized in the following table. The table also shows the port range used for these projects to ensure consistency throughout the book:
Microservice |
Projects |
Port Range |
---|---|---|
Book microservice |
|
|
Check-in microservice |
|
|
Fare microservice |
|
|
Search microservice |
|
|
Website |
|
|
The website is the UI application for testing the PSS microservices.
All microservice projects in this example follow the same pattern for package structure as shown in the following screenshot:
The different packages and their purposes are explained as follows:
com.brownfield.pss.book
) contains the default Spring Boot application.component
package hosts all the service components where the business logic is implemented.controller
package hosts the REST endpoints and the messaging endpoints. Controller classes internally utilize the component classes for execution.entity
package contains the JPA entity classes for mapping to the database tables.repository
package, and are based on Spring Data JPA.Follow the steps listed next to build and test the microservices developed in this chapter:
test
flag is switched off. The test programs assume other dependent services are up and running. It fails if the dependent services are not available. In our example, Booking and Fare have direct dependencies. We will learn how to circumvent this dependency in Chapter 7, Logging and Monitoring Microservices:mvn -Dmaven.test.skip=true install
rabbitmq_server-3.5.6/sbin$ ./rabbitmq-server
java -jar target/fares-1.0.jar java -jar target/search-1.0.jar java -jar target/checkin-1.0.jar java -jar target/book-1.0.jar java -jar target/website-1.0.jar
CommandLineRunner
, which executes all the test cases at startup. Once all the services are successfully started, open http://localhost:8001
in a browser.guest
or guest123
as the credentials. This example only shows the website security with a basic authentication mechanism. As explained in Chapter 2, Building Microservices with Spring Boot, service-level security can be achieved using OAuth2.