-
Notifications
You must be signed in to change notification settings - Fork 10
Microservice structure
In this page we introduce the microservice structure. This includes the folder, package and class structure. For the following descriptions we are using the fictional microservice: my-ms
Our microservices are maven projects with the following structure:
my-ms
|-- .gitignore
|-- pom.xml
`-- src
`-- main
|-- java
| `-- org
| `-- dice_research
| `-- sask
| `-- my_ms
| -- MyMsApplication.java
| -- MyMsController.java
| -- IMyMsService.java
| -- MyMsService.java
|-- resources
| -- application.yml
`-- test
|-- java
| `-- org
| `-- dice_research
| `-- sask
| `-- my_ms
This class is responsible to starting the microservice as Eureka client. The following code shows the code with the annotaions.
@SpringBootApplication
@EnableDiscoveryClient
public class MyMsApplication {
public static void main(String[] args) {
SpringApplication.run(MyMsApplication.class, args);
}
}
The controller class provides a REST interface for other microservices and web applications. This class should just take incoming requests and prepare they.
@RestController
public class MyMsController {
private Logger logger = Logger.getLogger(MyMsController.class.getName());
@RequestMapping(value = "/foo")
public boolean foo(String x) {
logger.info(myMs foo() invoked)
...
}
}
The service class implements the methods of the IService interface. This methods should include the real logic of the microservice. In our project is a typical example forwarding of data.
This config file is descripted in page "Microservice type"