Contents
Microservice Concerns
In this course, we will learn the concepts of microservice and spring framework and focus on Microservice concerns.
Learning Objectives
- Health Checks
- Alerts
- Error Handling
- Security
Intended Audience
- Beginner Java developers
- Java developers interested in learning how to Build and Deploy RESTful Web Services
- Java Developers who want to develop web applications using the Spring framework
- Java Developers who want to develop web applications with microservices
- Java Developers who wish to develop Spring Boot Microservices with Spring Cloud
Prerequisites
- Basic Java knowledge
Hello, my dear friends. In this lesson, we will talk about packaging options for rest services that make up a microservice architecture. You know that the microservices concept is tightly related to cloud computing and containerization. So, packaging became more important as cloud containerization became more common. So, there are two main packaging types for Java microservices applications: jar and Binary Executable. All runtime platforms like Open Liberty, Quadcast, WildFly, provide the jar packaging option. We can generate jar executables using the Maven runtime plugin of the related platform. To generate binary executable, a third party product is used. It is GraalVM, you can generate binary executable, using it for almost all major operating systems. It's available as either a Maven plugin or command line tool. I want to generate jar files for our services and start them from jar files. First, I will generate jar executable for NIN service. Right click on NIN service, select 'Run As', Maven build. Write liberty:package into goals box.
Click 'Add' button on the parameters part. Write include as a name and minify,runnable for the value box. Click 'Run'. As you see on the console, a jar file generated. Let's open a terminal in Eclipse IDE. Right-click on NIN service, select 'Shown In' terminal. Here, enter target folder. List the files. There's a jar file we have just generated. Let's run it. Just writing java -jar, the jar file. It started. Let's make some curl operations and try to generate numbers using the service. As you see, it works. Let's generate jar file for the citizen service. Right-click on the citizen service. Select 'Run As' Maven build. Write liberty:package into the goals box. Add include parameter with minify,runnable value. Click 'Run' button. Okay, created. Open a terminal for citizen service. Enter the target directory. List the files. Okay, as you see, here is the jar file. Okay, run it using java -jar command. Okay, the service started. Let's do curl operations and test them. As you can see, we can register a citizen, so that means they work well.
Now, stop NIN service and try again to register a citizen. To stop NIN service, just press 'Ctrl + C'. Now, try to make a POST request to citizen service. As you see, the fallback function became active, so everything is normal. One last thing I want to mention, users tend to use binary executable instead of jar files, because binary executable files have a smaller memory footprint and better portability. Okay, that was my tip. So, see you in the next lesson, dear friends.
OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.